Skip to content

Commit

Permalink
Update (#37)
Browse files Browse the repository at this point in the history
* Combine the two variables are both empty functions in variable noop

* Remove useless check

* Fix comment with obscene lexica
  • Loading branch information
ilyar authored and dfilatov committed Aug 10, 2017
1 parent 8f1e3b9 commit 6a916d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/inherit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

(function(global) {

var hasIntrospection = (function(){return '_';}).toString().indexOf('_') > -1,
emptyBase = function() {},
var noop = function() {},
hasOwnProperty = Object.prototype.hasOwnProperty,
objCreate = Object.create || function(ptp) {
var inheritance = function() {};
Expand Down Expand Up @@ -36,11 +35,10 @@ var hasIntrospection = (function(){return '_';}).toString().indexOf('_') > -1,
isFunction = function(obj) {
return toStr.call(obj) === '[object Function]';
},
noOp = function() {},
needCheckProps = true,
testPropObj = { toString : '' };

for(var i in testPropObj) { // fucking ie hasn't toString, valueOf in for
for(var i in testPropObj) { // It's a pity ie hasn't toString, valueOf in for
testPropObj.hasOwnProperty(i) && (needCheckProps = false);
}

Expand Down Expand Up @@ -69,13 +67,13 @@ function override(base, res, add) {
prop = add[name];
if(isFunction(prop) &&
(!prop.prototype || !prop.prototype.__self) && // check to prevent wrapping of "class" functions
(!hasIntrospection || prop.toString().indexOf('.__base') > -1)) {
(prop.toString().indexOf('.__base') > -1)) {
res[name] = (function(name, prop) {
var baseMethod = base[name]?
base[name] :
name === '__constructor'? // case of inheritance from plain function
res.__self.__parent :
noOp,
noop,
result = function() {
var baseSaved = this.__base;

Expand Down Expand Up @@ -121,7 +119,7 @@ function inherit() {
var args = arguments,
withMixins = isArray(args[0]),
hasBase = withMixins || isFunction(args[0]),
base = hasBase? withMixins? applyMixins(args[0]) : args[0] : emptyBase,
base = hasBase? withMixins? applyMixins(args[0]) : args[0] : noop,
props = args[hasBase? 1 : 0] || {},
staticProps = args[hasBase? 2 : 1],
res = props.__constructor || (hasBase && base.prototype && base.prototype.__constructor)?
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ exports.testInstanceOfConstructorResult = function(test) {
test.done();
};

exports.testInstanceOfSelfSimple = function(test) {
var Base = inherit({
prop : 'foo'
});
var A = inherit([Base]);
var actual = new A();

test.equal(actual.prop, 'foo');
test.done();
};

exports.testInstanceOfSelf = function(test) {
var A = inherit({
method : function () {
Expand Down

0 comments on commit 6a916d9

Please sign in to comment.