Coder Social home page Coder Social logo

setprototypeof's Introduction

Polyfill for Object.setPrototypeOf

NPM Version NPM Downloads js-standard-style

A simple cross platform implementation to set the prototype of an instantiated object. Supports all modern browsers and at least back to IE8.

Usage:

$ npm install --save setprototypeof
var setPrototypeOf = require('setprototypeof')

var obj = {}
setPrototypeOf(obj, {
  foo: function () {
    return 'bar'
  }
})
obj.foo() // bar

TypeScript is also supported:

import setPrototypeOf from 'setprototypeof'

setprototypeof's People

Contributors

longlho avatar mad-gooze avatar phapdinh avatar wesleytodd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

setprototypeof's Issues

IE9/10 and inheritance

Hi @wesleytodd, thanks for the package! It looks simple and very well-used.

By my testing, this does not behave correctly on IE9/10 - is that correct? What I mean is the problem described here, where changes to the parent prototype aren't reflected in the child:

var foo = { a: 1 };
var bar = { b: 2 };
setPrototypeOf(bar, foo);
bar.a; // 1
foo.a = 2;
bar.a; // 1 - should be 2

IE9/10 do not have setPrototypeOf or __proto__, which means that they will default to the mixinProperties definition. Looks like that just copies the properties with no link. My testing confirms that bar.a returns 1 instead of 2 at the end, using setPrototypeOf() in IE9/10.

Is this deliberate? I believe I could fix the behaviour, let me know and I'll submit a PR.

Edit: Changed the example to use the setPrototypeOf() syntax.

module undefined

Hi,

I get module is undefined error in ie10 when i include this polyfill. How do i fix it?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.