diff options
author | isaacs <i@izs.me> | 2013-09-07 23:21:39 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-09-07 23:21:39 +0400 |
commit | e703217e28869b49b25e9f8524084becc65de468 (patch) | |
tree | 9dd7272774676caf155f19bcfb7ec4d76dee7a09 /node_modules/inherits | |
parent | 5a8604bd4444a875452f56271e70927dd738c533 (diff) |
inherits-fixup
Diffstat (limited to 'node_modules/inherits')
-rw-r--r-- | node_modules/inherits/inherits_browser.js | 23 | ||||
-rw-r--r-- | node_modules/inherits/test.js | 25 |
2 files changed, 48 insertions, 0 deletions
diff --git a/node_modules/inherits/inherits_browser.js b/node_modules/inherits/inherits_browser.js new file mode 100644 index 000000000..c1e78a75e --- /dev/null +++ b/node_modules/inherits/inherits_browser.js @@ -0,0 +1,23 @@ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} diff --git a/node_modules/inherits/test.js b/node_modules/inherits/test.js new file mode 100644 index 000000000..fc53012d3 --- /dev/null +++ b/node_modules/inherits/test.js @@ -0,0 +1,25 @@ +var inherits = require('./inherits.js') +var assert = require('assert') + +function test(c) { + assert(c.constructor === Child) + assert(c.constructor.super_ === Parent) + assert(Object.getPrototypeOf(c) === Child.prototype) + assert(Object.getPrototypeOf(Object.getPrototypeOf(c)) === Parent.prototype) + assert(c instanceof Child) + assert(c instanceof Parent) +} + +function Child() { + Parent.call(this) + test(this) +} + +function Parent() {} + +inherits(Child, Parent) + +var c = new Child +test(c) + +console.log('ok') |