underscore-inherit
Advanced tools
Comparing version 0.0.1 to 0.0.2
20
index.js
@@ -1,2 +0,2 @@ | ||
(function() { | ||
(function () { | ||
'use strict'; | ||
@@ -10,3 +10,3 @@ | ||
_.mixin({ | ||
inherit: function (Parent, proto, static) { | ||
inherit: function (Parent, protoProps, staticProps) { | ||
@@ -16,17 +16,17 @@ // `Child` is the passed in `constructor` proto property | ||
var Child = | ||
proto && _.has(proto, 'constructor') ? | ||
proto.constructor : | ||
protoProps && _.has(protoProps, 'constructor') ? | ||
protoProps.constructor : | ||
function () { return Parent.apply(this, arguments); }; | ||
// `Dummy` is a dummy function to ensure `Parent.constructor` | ||
// `Dummy` is a dummy constructor to ensure `Parent.constructor` | ||
// isn't actually called as it could have unintended | ||
// side effects | ||
function Dummy() { this.constructor = Child; }; | ||
var Dummy = function () { this.constructor = Child; }; | ||
// Pass on convenience `__super__` and `static` properties | ||
_.extend(Child, Parent, {__super__: Parent.prototype}, static); | ||
// Pass on static properties | ||
_.extend(Child, Parent, staticProps); | ||
// Set up inheritance and merge `proto` properties | ||
// Set up inheritance and merge prototype properties | ||
Dummy.prototype = Parent.prototype; | ||
Child.prototype = _.extend(new Dummy, proto); | ||
Child.prototype = _.extend(new Dummy(), protoProps); | ||
@@ -33,0 +33,0 @@ // Return the finished constructor |
{ | ||
"name": "underscore-inherit", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Casey Foster <c@sey.me>", | ||
@@ -8,2 +8,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
@@ -20,12 +20,16 @@ underscore-inherit | ||
_.extend(Animal.prototype, { | ||
name: 'Chupacabra' | ||
sound: 'roarmeowbarkmoo', | ||
sing: function () { | ||
alert(Array(5).join(this.sound)); | ||
alert(this.name + ' says ' + Array(5).join(this.sound)); | ||
} | ||
}); | ||
var Dog = _.inherit(Animal, { | ||
name: 'Gunner', | ||
sound: 'woof' | ||
}); | ||
var Dog = _.inherit(Animal, { | ||
var Cat = _.inherit(Animal, { | ||
name: 'Mittens', | ||
sound: 'meow' | ||
@@ -32,0 +36,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2984
41