can-construct-super
Advanced tools
Comparing version 3.0.3 to 3.1.0-pre.0
/* global require, module */ | ||
var can = require('can-util'); | ||
var Construct = require('can-construct'); | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
// tests if we can get super in .toString() | ||
@@ -12,11 +13,30 @@ var isFunction = can.isFunction, | ||
return function () { | ||
var tmp = this._super, | ||
ret; | ||
// Add a new ._super() method that is the same method | ||
// but on the super-class | ||
this._super = base[name]; | ||
var hasExistingValue = false; | ||
var existingValue; | ||
var prototype = getPrototypeOf(this); | ||
var existingPrototypeValue = prototype._super; | ||
/* We must delete the instance's _super so the lookup | ||
will reach the prototype. */ | ||
if (hasOwnProperty.call(this, '_super')) { | ||
hasExistingValue = true; | ||
existingValue = this._super; | ||
/* NOTE: if the object is sealed this will not work. | ||
The '_super' key cannot be used on the instance | ||
in that rare case. */ | ||
delete this._super; | ||
} | ||
/* Add a new ._super() method that is the same method | ||
but on the super-class. It must be set on the prototype | ||
because the instance may be sealed. */ | ||
prototype._super = base[name]; | ||
// The method only need to be bound temporarily, so we | ||
// remove it when we're done executing | ||
ret = fn.apply(this, arguments); | ||
this._super = tmp; | ||
var ret = fn.apply(this, arguments); | ||
prototype._super = existingPrototypeValue; | ||
if (hasExistingValue) { | ||
this._super = existingValue; | ||
} | ||
return ret; | ||
@@ -23,0 +43,0 @@ }; |
{ | ||
"name": "can-construct-super", | ||
"version": "3.0.3", | ||
"version": "3.1.0-pre.0", | ||
"description": "Provides a reference to the prototypal parent using this._super in can-construct objects", | ||
@@ -9,7 +9,7 @@ "main": "can-construct-super", | ||
"version": "git commit -am \"Update dist for release\" && git checkout -b release && git add -f dist/", | ||
"postversion": "git push --tags && git checkout master && git branch -D release && git push", | ||
"postversion": "git push --tags && git checkout can-reflect && git branch -D release && git push", | ||
"testee": "testee test/test.html --browsers firefox", | ||
"test": "npm run jshint && npm run testee", | ||
"jshint": "jshint ./*.js --config", | ||
"release:pre": "npm version prerelease && npm publish", | ||
"release:pre": "npm version prerelease && npm publish --tag=pre", | ||
"release:patch": "npm version patch && npm publish", | ||
@@ -37,4 +37,4 @@ "release:minor": "npm version minor && npm publish", | ||
"dependencies": { | ||
"can-construct": "^3.0.0", | ||
"can-util": "^3.0.0" | ||
"can-construct": "^3.2.0-pre.0", | ||
"can-util": "^3.9.0-pre.4" | ||
}, | ||
@@ -41,0 +41,0 @@ "devDependencies": { |
@@ -127,1 +127,25 @@ /* global require, test, stop, start, expect, equal, Promise */ | ||
}); | ||
QUnit.test("_super should work for sealed instances", function () { | ||
var A = Construct.extend({ | ||
init: function (arg) { | ||
this.arg = arg + 1; | ||
}, | ||
add: function (num) { | ||
return this.arg + num; | ||
} | ||
}); | ||
var B = A({ | ||
init: function (arg) { | ||
this._super(arg + 2); | ||
}, | ||
add: function (arg) { | ||
console.log(this) | ||
return this._super(arg + 1); | ||
} | ||
}); | ||
var b = new B(1); | ||
Object.seal(b); | ||
equal(b.arg, 4, 'should instantiate properly'); | ||
equal(b.add(2), 7, 'should call methods properly'); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13976
234
1
Updatedcan-construct@^3.2.0-pre.0
Updatedcan-util@^3.9.0-pre.4