Skip to content

Commit

Permalink
ExtendJS 0.2.3
Browse files Browse the repository at this point in the history
Fixed issues where the constructors scope would be lost if the class
was initialised from a this reference inside another class.
  • Loading branch information
Benjaminsen committed Jan 16, 2015
1 parent f834531 commit 28329be
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions bin/extend.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
ExtendJS 0.2.2
ExtendJS 0.2.3
More info at http://extendjs.org
Copyright (c) 2013+ ChrisBenjaminsen.com
Expand All @@ -9,4 +9,4 @@ http://extendjs.org/licence.txt
This notice shall be included in all copies or substantial portions of the Software.
*/
!function(a){"use strict";function b(a){a.parent instanceof Function&&(b.apply(this,[a.parent]),this.super=c(this,d(this,this.constructor))),a.apply(this,arguments)}function c(a,b){for(var c in a)"super"!==c&&a[c]instanceof Function&&(b[c]=a[c].super||d(a,a[c]));return b}function d(a,b){var c=a.super;return b.super=function(){return a.super=c,b.apply(a,arguments)}}a.Class=function(){},a.Class.extend=function e(a){function d(){b!==arguments[0]&&(b.apply(this,[a]),c(this,this),this.initializer instanceof Function&&this.initializer.apply(this),this.constructor.apply(this,arguments))}return d.prototype=new this(b),d.prototype.constructor=d,d.toString=function(){return a.toString()},d.extend=function(b){return b.parent=a,e.apply(d,arguments)},d},a.Class=a.Class.extend(function(){this.constructor=function(){}})}(this);
!function(a){"use strict";function b(a){a.parent instanceof Function&&(b.apply(this,[a.parent]),this.super=c(this,d(this,this.constructor))),a.apply(this,arguments)}function c(a,b){for(var c in a)"super"!==c&&a[c]instanceof Function&&!(a[c].prototype instanceof Class)&&(b[c]=a[c].super||d(a,a[c]));return b}function d(a,b){var c=a.super;return b.super=function(){return a.super=c,b.apply(a,arguments)}}a.Class=function(){},a.Class.extend=function e(a){function d(){b!==arguments[0]&&(b.apply(this,[a]),c(this,this),this.initializer instanceof Function&&this.initializer.apply(this),this.constructor.apply(this,arguments))}return d.prototype=new this(b),d.prototype.constructor=d,d.toString=function(){return a.toString()},d.extend=function(b){return b.parent=a,e.apply(d,arguments)},d},a.Class=a.Class.extend(function(){this.constructor=function(){}})}(this);
9 changes: 7 additions & 2 deletions src/extend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
ExtendJS 0.2.2
ExtendJS 0.2.3
More info at http://extendjs.org
Copyright (c) 2013+ ChrisBenjaminsen.com
Expand Down Expand Up @@ -39,7 +39,11 @@
//Helper method which allows for super referances.
function cloneCopy(from, to){
for(var x in from){
if(x !== "super" && from[x] instanceof Function){
if(
x !== "super" && //Never clone the super referance
from[x] instanceof Function && //Only overwrite functions
!(from[x].prototype instanceof Class) //Never overwrite referances to classes
){
//Never create circular super referances.
to[x] = from[x].super || superCopy(from, from[x]);
}
Expand All @@ -53,6 +57,7 @@
scope.super = scopeSuper;
return method.apply(scope, arguments);
}
return method;
}

//Create Class object
Expand Down
12 changes: 0 additions & 12 deletions tests/extend.min.js

This file was deleted.

39 changes: 32 additions & 7 deletions tests/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,33 @@
}
})





var order = []
var RootClass = Class.extend(function() {
this.doSomething = function() {
order.push("rd")
};
});

var Child1 = RootClass.extend(function() {
this.test = RootClass;
this.constructor = function() {
order.push("c1")
this.child = new this.test();
};
this.doSomething = function() {
order.push("1d")
this.child.doSomething();
}
});

var Child2 = Child1.extend(function() {
this.constructor = function() {
order.push("c2")
this.super();
}
});


new newClass()
new newClass2()

Expand All @@ -135,15 +158,17 @@
WriteUnitTest(new myClass4().wrapper("test") == "1234test", "Testing that third level internal method calls works")
WriteUnitTest(new myClass5().toptest("") == "-*", "Validate if inherited methods does not clone incorrectly")
new PrototypeTestClass3()
WriteUnitTest(didExecute == "Success", "Testing if we can call constructor via non existing constructor overwrite")//*/
WriteUnitTest(didExecute == "Success", "Testing if we can call constructor via non existing constructor overwrite")
WriteUnitTest(new ChildClass().test() == "||--**", "Secound validation for complex scopes")
WriteUnitTest(shouldNotBeCalled, "Testing that getters are not being called during class cloning")
new Child2().doSomething();
WriteUnitTest(order.join("|") == "c2|c1|1d|rd", "Verifying that locally stored referances to Classes are scope safe")//*/

var bef = new Date().getTime();
/*var bef = new Date().getTime();
for( var a=0;a<100000;a++){
var d = new myClass4()
}
console.log(new Date().getTime()-bef)
console.log(new Date().getTime()-bef)*/


</script>
Expand Down

0 comments on commit 28329be

Please sign in to comment.