+29
-1
@@ -1,1 +0,29 @@ | ||
| module.exports = require('util').inherits | ||
| module.exports = inherits | ||
| function inherits (c, p, proto) { | ||
| proto = proto || {} | ||
| var e = {} | ||
| ;[c.prototype, proto].forEach(function (s) { | ||
| Object.getOwnPropertyNames(s).forEach(function (k) { | ||
| e[k] = Object.getOwnPropertyDescriptor(s, k) | ||
| }) | ||
| }) | ||
| c.prototype = Object.create(p.prototype, e) | ||
| c.super = p | ||
| } | ||
| //function Child () { | ||
| // Child.super.call(this) | ||
| // console.error([this | ||
| // ,this.constructor | ||
| // ,this.constructor === Child | ||
| // ,this.constructor.super === Parent | ||
| // ,Object.getPrototypeOf(this) === Child.prototype | ||
| // ,Object.getPrototypeOf(Object.getPrototypeOf(this)) | ||
| // === Parent.prototype | ||
| // ,this instanceof Child | ||
| // ,this instanceof Parent]) | ||
| //} | ||
| //function Parent () {} | ||
| //inherits(Child, Parent) | ||
| //new Child |
+7
-22
@@ -1,22 +0,7 @@ | ||
| { | ||
| "name": "inherits", | ||
| "description": "Browser-friendly inheritance fully compatible with standard node.js inherits()", | ||
| "version": "1.0.1", | ||
| "keywords": [ | ||
| "inheritance", | ||
| "class", | ||
| "klass", | ||
| "oop", | ||
| "object-oriented", | ||
| "inherits", | ||
| "browser", | ||
| "browserify" | ||
| ], | ||
| "main": "./inherits.js", | ||
| "browser": "./inherits_browser.js", | ||
| "repository": "git://github.com/isaacs/inherits", | ||
| "license": "ISC", | ||
| "scripts": { | ||
| "test": "node test" | ||
| } | ||
| } | ||
| { "name" : "inherits" | ||
| , "description": "A tiny simple way to do classic inheritance in js" | ||
| , "version" : "1.0.2" | ||
| , "keywords" : ["inheritance", "class", "klass", "oop", "object-oriented"] | ||
| , "main" : "./inherits.js" | ||
| , "repository" : "https://github.com/isaacs/inherits" | ||
| , "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)" } |
+43
-34
@@ -1,42 +0,51 @@ | ||
| Browser-friendly inheritance fully compatible with standard node.js | ||
| [inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor). | ||
| A dead simple way to do inheritance in JS. | ||
| This package exports standard `inherits` from node.js `util` module in | ||
| node environment, but also provides alternative browser-friendly | ||
| implementation through [browser | ||
| field](https://gist.github.com/shtylman/4339901). Alternative | ||
| implementation is a literal copy of standard one located in standalone | ||
| module to avoid requiring of `util`. It also has a shim for old | ||
| browsers with no `Object.create` support. | ||
| var inherits = require("inherits") | ||
| While keeping you sure you are using standard `inherits` | ||
| implementation in node.js environment, it allows bundlers such as | ||
| [browserify](https://github.com/substack/node-browserify) to not | ||
| include full `util` package to your client code if all you need is | ||
| just `inherits` function. It worth, because browser shim for `util` | ||
| package is large and `inherits` is often the single function you need | ||
| from it. | ||
| function Animal () { | ||
| this.alive = true | ||
| } | ||
| Animal.prototype.say = function (what) { | ||
| console.log(what) | ||
| } | ||
| It's recommended to use this package instead of | ||
| `require('util').inherits` for any code that has chances to be used | ||
| not only in node.js but in browser too. | ||
| inherits(Dog, Animal) | ||
| function Dog () { | ||
| Dog.super.apply(this) | ||
| } | ||
| Dog.prototype.sniff = function () { | ||
| this.say("sniff sniff") | ||
| } | ||
| Dog.prototype.bark = function () { | ||
| this.say("woof woof") | ||
| } | ||
| ## usage | ||
| inherits(Chihuahua, Dog) | ||
| function Chihuahua () { | ||
| Chihuahua.super.apply(this) | ||
| } | ||
| Chihuahua.prototype.bark = function () { | ||
| this.say("yip yip") | ||
| } | ||
| ```js | ||
| var inherits = require('inherits'); | ||
| // then use exactly as the standard one | ||
| ``` | ||
| // also works | ||
| function Cat () { | ||
| Cat.super.apply(this) | ||
| } | ||
| Cat.prototype.hiss = function () { | ||
| this.say("CHSKKSS!!") | ||
| } | ||
| inherits(Cat, Animal, { | ||
| meow: function () { this.say("miao miao") } | ||
| }) | ||
| Cat.prototype.purr = function () { | ||
| this.say("purr purr") | ||
| } | ||
| ## note on version ~1.0 | ||
| Version ~1.0 had completely different motivation and is not compatible | ||
| neither with 2.0 nor with standard node.js `inherits`. | ||
| var c = new Chihuahua | ||
| assert(c instanceof Chihuahua) | ||
| assert(c instanceof Dog) | ||
| assert(c instanceof Animal) | ||
| If you are using version ~1.0 and planning to switch to ~2.0, be | ||
| careful: | ||
| * new version uses `super_` instead of `super` for referencing | ||
| superclass | ||
| * new version overwrites current prototype while old one preserves any | ||
| existing fields on it | ||
| The actual function is laughably small. 10-lines small. |
| 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 | ||
| } | ||
| } |
-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') |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
2
-33.33%52
20.93%3058
-24.92%4
-33.33%27
-37.21%