\r
describe("base.js", function() {\r
it("cascading inherit", function() {\r
- var gl = (function(){ return this; })(); // Global Object\r
- gl.$parent = gl.base( function() {\r
+ base("$parent").mix( function() {\r
this.hoge = function() {\r
return 12;\r
};\r
- this.$child = this.base( function() {\r
+ this.up("$child").mix( function() {\r
this.hoge = function() {\r
return this.$parent.hoge();\r
};\r
});\r
});\r
- gl.$parent.$child.hoge(); //12\r
+ base("$parent").$child.hoge(); //12\r
});\r
});\r
</script>\r
See Also MIT-LICENSE.txt\r
Copyright (c) 2013 dhrname*/\r
\r
-if (!this.base) {\r
- this.base= function(obj) {\r
- if (!arguments[0]) {\r
- throw new Error("no arguments error");\r
- }\r
+function base(name) {\r
+ if (!arguments[0]) {\r
+ throw new Error("No arguments errror");\r
+ } else if (this[name]) {\r
+ /*id\93o\98^\82³\82ê\82Ä\82¢\82é\8fê\8d\87\82Í\81A\93o\98^\82³\82ê\82½\83I\83u\83W\83F\83N\83g\82ð\95Ô\82·*/\r
+ return this[name];\r
+ } else {\r
var F = function() {},\r
s;\r
F.prototype = this;\r
s = new F();\r
- if (typeof obj !== "function") {\r
- for (var i in obj) {\r
- if (obj.hasOwnProperty(i)) {\r
- s[i] = obj[i];\r
- }\r
+ s.mix = base.mix;\r
+ s.up = base;\r
+ this[name] = s;\r
+ /*IE 8\82Å\82Í\81A\83O\83\8d\81[\83o\83\8b\83I\83u\83W\83F\83N\83g\82Ì\83v\83\8d\83g\83^\83C\83v\8cp\8f³\82ª\82¤\82Ü\82\82¢\82©\82È\82¢\82½\82ß\81A\r
+ *\8e\9f\82Ì\82æ\82¤\82È\8e©\90g\82ª\92l\82Å\82 \82é\82æ\82¤\82È\83v\83\8d\83p\83e\83B\82ð\90Ý\92è\82·\82é\r
+ */\r
+ s[name] = s;\r
+ F = void 0;\r
+ return s; \r
+ }\r
+ };\r
+ base.mix = function(obj) {\r
+ if (!arguments[0]) {\r
+ throw new Error("No arguments errror");\r
+ }\r
+ if (typeof obj !== "function") {\r
+ for (var i in obj) {\r
+ if (obj.hasOwnProperty(i)) {\r
+ this[i] = obj[i];\r
}\r
- } else {\r
- obj.call(s);\r
}\r
- F = void 0;\r
- return s;\r
- };\r
-}
\ No newline at end of file
+ } else {\r
+ obj.call(this);\r
+ }\r
+ return this;\r
+ };
\ No newline at end of file