From 750fd4cc486fb0d29863192950173d19902f524c Mon Sep 17 00:00:00 2001 From: dhrname Date: Fri, 3 Jan 2014 23:54:36 +0900 Subject: [PATCH] =?utf8?q?BaseJS=E3=82=92IE=208=E3=81=AB=E5=AF=BE=E5=BF=9C?= =?utf8?q?=E3=81=95=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tool/funcproto/FuncSpecRunner.html | 7 +++--- tool/funcproto/base.js | 47 +++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/tool/funcproto/FuncSpecRunner.html b/tool/funcproto/FuncSpecRunner.html index e575704..131423f 100644 --- a/tool/funcproto/FuncSpecRunner.html +++ b/tool/funcproto/FuncSpecRunner.html @@ -164,18 +164,17 @@ describe("Async::Sleep4", function() { describe("base.js", function() { it("cascading inherit", function() { - var gl = (function(){ return this; })(); // Global Object - gl.$parent = gl.base( function() { + base("$parent").mix( function() { this.hoge = function() { return 12; }; - this.$child = this.base( function() { + this.up("$child").mix( function() { this.hoge = function() { return this.$parent.hoge(); }; }); }); - gl.$parent.$child.hoge(); //12 + base("$parent").$child.hoge(); //12 }); }); diff --git a/tool/funcproto/base.js b/tool/funcproto/base.js index e6f587d..1432e43 100644 --- a/tool/funcproto/base.js +++ b/tool/funcproto/base.js @@ -2,25 +2,40 @@ See Also MIT-LICENSE.txt Copyright (c) 2013 dhrname*/ -if (!this.base) { - this.base= function(obj) { - if (!arguments[0]) { - throw new Error("no arguments error"); - } +function base(name) { + if (!arguments[0]) { + throw new Error("No arguments errror"); + } else if (this[name]) { + /*id“o˜^‚³‚ê‚Ä‚¢‚éê‡‚́A“o˜^‚³‚ꂽƒIƒuƒWƒFƒNƒg‚ð•Ô‚·*/ + return this[name]; + } else { var F = function() {}, s; F.prototype = this; s = new F(); - if (typeof obj !== "function") { - for (var i in obj) { - if (obj.hasOwnProperty(i)) { - s[i] = obj[i]; - } + s.mix = base.mix; + s.up = base; + this[name] = s; + /*IE 8‚ł́AƒOƒ[ƒoƒ‹ƒIƒuƒWƒFƒNƒg‚̃vƒƒgƒ^ƒCƒvŒp³‚ª‚¤‚Ü‚­‚¢‚©‚È‚¢‚½‚߁A + *ŽŸ‚̂悤‚ÈŽ©g‚ª’l‚Å‚ ‚é‚悤‚ȃvƒƒpƒeƒB‚ðÝ’è‚·‚é + */ + s[name] = s; + F = void 0; + return s; + } + }; + base.mix = function(obj) { + if (!arguments[0]) { + throw new Error("No arguments errror"); + } + if (typeof obj !== "function") { + for (var i in obj) { + if (obj.hasOwnProperty(i)) { + this[i] = obj[i]; } - } else { - obj.call(s); } - F = void 0; - return s; - }; -} \ No newline at end of file + } else { + obj.call(this); + } + return this; + }; \ No newline at end of file -- 2.11.0