diff --git a/dist/namespace.js b/dist/namespace.js index 3681a32..201daeb 100644 --- a/dist/namespace.js +++ b/dist/namespace.js @@ -120,10 +120,12 @@ { superClass = window.include(superClass); } + subClass.prototype = superClass.prototype; + subClass.prototype.__parent = superClass.prototype; subClass.prototype = Object.create( - superClass.prototype + subClass.prototype ); return subClass.prototype; }; -}(window)); \ No newline at end of file +}(window)); diff --git a/dist/namespace.min.js b/dist/namespace.min.js index ad6c089..873c105 100644 --- a/dist/namespace.min.js +++ b/dist/namespace.min.js @@ -1,2 +1,2 @@ /*! namespace 1.2.0 */ -!function(){"use strict";!function(a){"namespace"in a||(a.namespace=function(b){for(var c=b.split("."),d=a,e="",f=0,g=c.length;g>f;f++)e=c[f],d[e]=d[e]||{},d=d[e];return d})}(window),function(a,b){"include"in a||(a.include=function(c,d){var e=c.split("."),f=a,g="";d=d!==b?!!d:!0;for(var h=0,i=e.length;i>h;h++){if(g=e[h],!f[g]){if(!d)return null;throw"Unable to include '"+c+"'"}f=f[g]}return f})}(window),function(a){"extend"in a||(a.extend=function(b,c){return"string"==typeof c&&(c=a.include(c)),b.prototype=Object.create(c.prototype),b.prototype})}(window);}(); \ No newline at end of file +!function(){"use strict";!function(a){"namespace"in a||(a.namespace=function(b){for(var c=b.split("."),d=a,e="",f=0,g=c.length;g>f;f++)e=c[f],d[e]=d[e]||{},d=d[e];return d})}(window),function(a,b){"include"in a||(a.include=function(c,d){var e=c.split("."),f=a,g="";d=d!==b?!!d:!0;for(var h=0,i=e.length;i>h;h++){if(g=e[h],!f[g]){if(!d)return null;throw"Unable to include '"+c+"'"}f=f[g]}return f})}(window),function(a){"extend"in a||(a.extend=function(b,c){return"string"==typeof c&&(c=a.include(c)),b.prototype=c.prototype,b.prototype.__parent=c.prototype,b.prototype=Object.create(b.prototype),b.prototype})}(window);}(); \ No newline at end of file diff --git a/src/extend.js b/src/extend.js index c599bd7..af55470 100644 --- a/src/extend.js +++ b/src/extend.js @@ -26,10 +26,12 @@ { superClass = window.include(superClass); } + subClass.prototype = superClass.prototype; + subClass.prototype.__parent = superClass.prototype; subClass.prototype = Object.create( - superClass.prototype + subClass.prototype ); return subClass.prototype; }; -}(window)); \ No newline at end of file +}(window)); diff --git a/test/index.html b/test/index.html index 24bac51..662080c 100644 --- a/test/index.html +++ b/test/index.html @@ -52,6 +52,24 @@ assert.ok(o instanceof ParentClass, "Inherit parent class"); }); + + test('extend.parent', function(assert){ + expect(3); + + var ParentClass = function(){}; + ParentClass.prototype.ping = function(){return "parent";} + var MyClass = function(){}; + + extend(MyClass, ParentClass); + MyClass.prototype.ping = function(){return "child";} + + var o = new MyClass(); + + assert.ok(o.ping() === "child", "Child function"); + assert.ok(o.__parent.ping.apply(o) === "parent", "Parent function"); + assert.ok(o.ping() !== o.__parent.ping.apply(o), "Child != Parent function"); + + }); - \ No newline at end of file +