underscore-inherit
Advanced tools
Comparing version 0.0.5 to 1.0.0
{ | ||
"name": "underscore-inherit", | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"main": "underscore-inherit.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
{ | ||
"name": "underscore-inherit", | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"author": "Casey Foster <c@sey.me>", | ||
@@ -5,0 +5,0 @@ "main": "underscore-inherit", |
@@ -17,5 +17,3 @@ underscore-inherit | ||
```js | ||
var Animal = function () {}; | ||
_.extend(Animal.prototype, { | ||
var Animal = _.inherit({ | ||
name: 'Chupacabra', | ||
@@ -28,6 +26,8 @@ sound: 'roarmeowbarkmoo', | ||
var Dog = _.inherit(Animal, { | ||
var HardWorker = _.inherit(); | ||
var Dog = _.inherit(Animal, HardWorker, { | ||
name: 'Gunner', | ||
sound: 'woof' | ||
}); | ||
}, {staticProp: 'hello'}); | ||
@@ -40,4 +40,12 @@ var Cat = _.inherit(Animal, { | ||
(new Animal()).sing(); | ||
(new Cat()).sing(); | ||
(new Dog()).sing(); | ||
(new Cat()).sing(); | ||
// (new Cat) instanceof Animal === true | ||
// (new Cat) instanceof Cat === true | ||
// Dog.staticProp === true | ||
// (new Dog) instanceof Animal === true | ||
// (new Dog) instanceof HardWorker === true | ||
// (new Dog) instanceof Dog === true | ||
``` |
@@ -10,3 +10,19 @@ (function () { | ||
_.mixin({ | ||
inherit: function (Parent, protoProps, staticProps) { | ||
inherit: function () { | ||
var protoProps; | ||
var staticProps; | ||
var Parent = _.reduce(arguments, function (Parent, arg) { | ||
if (_.isFunction(arg)) { | ||
if (!Parent) return arg; | ||
return _.inherit(arg, {constructor: Parent}); | ||
} | ||
if (_.isObject(arg)) { | ||
if (!protoProps) { | ||
protoProps = arg; | ||
} else if (!staticProps) { | ||
staticProps = arg; | ||
} | ||
} | ||
return Parent; | ||
}, null) || function () {}; | ||
@@ -13,0 +29,0 @@ // `Child` is the passed in `constructor` proto property |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
31954
8
52
1
49