dunder

0.1.1 • Public • Published

dunder

hot-swap inheritance for every engine

build status

API

  • dunder(object:Object):Object|null returns the object prototype
  • dunder(object:Object, proto:Object|null):object|Object returns an object that inherits from the second argument

If the engine supports a descriptor to set the prototype chain, or the __proto__, the object is not recreated, otherwise it's inherited and replicated on top using ES5+ descriptors for a uniformed behavior in IE10 and IE9 too.

// basics
var a = {}, b = {};
dunder(a) === Object.prototype; // true
 
// inline swap
= dunder(a, b);
b.isPrototypeOf(a); // true
dunder(a) === b;    // true
 
// hot-swap Zepto.js like
var libObj = dunder(
  document.querySelectorAll(CSS),
  MyAwesomeLibrary.prototype
);

That is pretty much it, except you might decide to make the environment safe, if needed, invoking free.

'__proto__' in Object.prototype; // true
dunder.free();

// only in certain cases and if possible
'__proto__' in Object.prototype; // false

The list of engines able to get rid of proto as getter/setter is not known yet.

Free From proto Problems

There is an extra method to try to get rid of __proto__ called dunder.free(), it returns a boolean if delete Object.prototype.__proto__ was successful, which should be the case with most recent JS engines.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.12latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.12
0.1.00

Package Sidebar

Install

npm i dunder

Weekly Downloads

2

Version

0.1.1

License

none

Last publish

Collaborators

  • webreflection