Skip to content

Instantly share code, notes, and snippets.

@ahouck
Created February 19, 2016 01:03
Show Gist options
  • Save ahouck/492a6f2ccedf083c2244 to your computer and use it in GitHub Desktop.
Save ahouck/492a6f2ccedf083c2244 to your computer and use it in GitHub Desktop.

Object.setPrototypeOf()

This sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null.

Generally considered the proper way to set the prototype of an object, vs. the more controversial Object.prototype.proto property.

var obj = Object.setPrototypeOf({}, null);

// Only works in Chrome and FireFox, does not work in IE:
Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
  obj.__proto__ = proto;
  return obj; 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment