From d6112dde07d1b9dabbd5683c78b342f01e6459e2 Mon Sep 17 00:00:00 2001 From: garrylachman Date: Wed, 30 Sep 2015 02:58:33 +0300 Subject: [PATCH 1/2] added parent call --- dist/namespace.js | 6 ++++-- dist/namespace.min.js | 2 +- src/extend.js | 6 ++++-- test/index.html | 20 +++++++++++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/dist/namespace.js b/dist/namespace.js index 3681a32..4046396 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..4cc7dec 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..f42e93a 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..3540d9b 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 + From ffd5727297ae7071012245b0916b124b5cb00057 Mon Sep 17 00:00:00 2001 From: garrylachman Date: Wed, 30 Sep 2015 16:48:38 +0300 Subject: [PATCH 2/2] change parent to __parent --- dist/namespace.js | 2 +- dist/namespace.min.js | 2 +- src/extend.js | 2 +- test/index.html | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/namespace.js b/dist/namespace.js index 4046396..201daeb 100644 --- a/dist/namespace.js +++ b/dist/namespace.js @@ -121,7 +121,7 @@ superClass = window.include(superClass); } subClass.prototype = superClass.prototype; - subClass.prototype.parent = superClass.prototype; + subClass.prototype.__parent = superClass.prototype; subClass.prototype = Object.create( subClass.prototype ); diff --git a/dist/namespace.min.js b/dist/namespace.min.js index 4cc7dec..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=c.prototype,b.prototype.parent=c.prototype,b.prototype=Object.create(b.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 f42e93a..af55470 100644 --- a/src/extend.js +++ b/src/extend.js @@ -27,7 +27,7 @@ superClass = window.include(superClass); } subClass.prototype = superClass.prototype; - subClass.prototype.parent = superClass.prototype; + subClass.prototype.__parent = superClass.prototype; subClass.prototype = Object.create( subClass.prototype ); diff --git a/test/index.html b/test/index.html index 3540d9b..662080c 100644 --- a/test/index.html +++ b/test/index.html @@ -66,8 +66,8 @@ 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"); + assert.ok(o.__parent.ping.apply(o) === "parent", "Parent function"); + assert.ok(o.ping() !== o.__parent.ping.apply(o), "Child != Parent function"); });