diff --git a/lib/tester.js b/lib/tester.js new file mode 100644 index 0000000..2e52519 --- /dev/null +++ b/lib/tester.js @@ -0,0 +1,143 @@ +(function() { + var C, D, S, T, Tester1, Tester2, mix, s, _, + __slice = Array.prototype.slice; + + _ = require('underscore'); + + console.log(_.isEmpty({})); + + return; + + mix = function(A, B) { + var x1, x2; + B.prototype.prototype = A.prototype; + x1 = {}; + x1.prototype = A.prototype; + x2 = {}; + return x2.prototype = A.prototype = B.prototype; + }; + + Function.prototype.include = function() { + var argv, cl, key, value, _i, _len, _ref; + argv = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + for (_i = 0, _len = argv.length; _i < _len; _i++) { + cl = argv[_i]; + _ref = cl.prototype; + for (key in _ref) { + value = _ref[key]; + this.prototype[key] = value; + } + } + return this; + }; + + Function.prototype.extend = function() { + var argv, cl, key, value, _i, _len, _ref; + argv = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + for (_i = 0, _len = argv.length; _i < _len; _i++) { + cl = argv[_i]; + _ref = cl.prototype; + for (key in _ref) { + value = _ref[key]; + this[key] = value; + } + } + return this; + }; + + Tester1 = (function() { + + function Tester1(name) { + this.name = name; + } + + Tester1.prototype.my_name = function() { + return console.log("Tester1 name is " + this.name); + }; + + return Tester1; + + })(); + + Tester2 = (function() { + + function Tester2(name) { + this.name = name; + } + + Tester2.prototype.my_name = function() { + return console.log("Tester2 name is " + this.name); + }; + + Tester2.prototype.other = function() { + return console.log("other"); + }; + + return Tester2; + + })(); + + C = (function() { + + function C(name) { + this.name = name; + } + + C.include(Tester1, Tester2); + + return C; + + })(); + + D = (function() { + + function D(name) { + this.name = name; + } + + D.extend(Tester2); + + return D; + + })(); + + T = (function() { + + function T(num) { + if (num == null) num = 0; + this.num = num; + if (num === 1) this.child = new arguments.callee; + } + + T.prototype.cal = function() { + return console.log(this); + }; + + return T; + + })(); + + S = (function() { + + function S() { + this.c = function() { + return console.log(this); + }; + this.a = "b"; + this.prot = arguments.callee.prototype; + } + + S.prototype.s = function() { + console.log(this); + return this.c(); + }; + + return S; + + })(); + + s = new S; + + console.log(s.constructor.prototype); + +}).call(this); diff --git a/lib/and.coffee b/src/and.coffee similarity index 100% rename from lib/and.coffee rename to src/and.coffee diff --git a/lib/array.coffee b/src/array.coffee similarity index 100% rename from lib/array.coffee rename to src/array.coffee diff --git a/lib/bool.coffee b/src/bool.coffee similarity index 100% rename from lib/bool.coffee rename to src/bool.coffee diff --git a/lib/date.coffee b/src/date.coffee similarity index 100% rename from lib/date.coffee rename to src/date.coffee diff --git a/lib/error.coffee b/src/error.coffee similarity index 100% rename from lib/error.coffee rename to src/error.coffee diff --git a/lib/eve.coffee b/src/eve.coffee similarity index 100% rename from lib/eve.coffee rename to src/eve.coffee diff --git a/lib/message-zh-CN.coffee b/src/message-zh-CN.coffee similarity index 100% rename from lib/message-zh-CN.coffee rename to src/message-zh-CN.coffee diff --git a/lib/message.coffee b/src/message.coffee similarity index 100% rename from lib/message.coffee rename to src/message.coffee diff --git a/lib/moduler.coffee b/src/moduler.coffee similarity index 100% rename from lib/moduler.coffee rename to src/moduler.coffee diff --git a/lib/number.coffee b/src/number.coffee similarity index 100% rename from lib/number.coffee rename to src/number.coffee diff --git a/lib/object.coffee b/src/object.coffee similarity index 100% rename from lib/object.coffee rename to src/object.coffee diff --git a/lib/or.coffee b/src/or.coffee similarity index 100% rename from lib/or.coffee rename to src/or.coffee diff --git a/lib/string.coffee b/src/string.coffee similarity index 100% rename from lib/string.coffee rename to src/string.coffee diff --git a/src/tester.coffee b/src/tester.coffee new file mode 100644 index 0000000..c6207fb --- /dev/null +++ b/src/tester.coffee @@ -0,0 +1,113 @@ +_ = require 'underscore' + +console.log _.isEmpty({}) +return + +mix = (A, B) -> + B.prototype.prototype = A.prototype + x1 = {} + x1.prototype = A.prototype + + x2 = {} + x2.prototype = + A.prototype = B.prototype + + +Function::include = (argv...) -> + for cl in argv + for key, value of cl:: + @::[key]=value + @ + +Function::extend = (argv...) -> + for cl in argv + for key, value of cl:: + @[key]=value + @ + + +class Tester1 + constructor: (name) -> + @name = name + my_name: -> + console.log "Tester1 name is " + @name + +class Tester2 + constructor: (name) -> + @name = name + my_name: -> + console.log "Tester2 name is " + @name + other: -> console.log "other" + +class C + constructor: (name) -> + @name = name + @include Tester1, Tester2 + +class D + constructor: (name) -> + @name = name + @extend Tester2 + + +#c = new C 'C' +#c.other() +#c.my_name() + +#D.other() + + +class T + constructor: (num=0) -> + @num = num + if num == 1 + @child = new arguments.callee + #console.log arguments.callee.toString() + + cal: () -> + console.log @ + #console.log arguments.callee.toString() + +#t = new T 1 +#t.cal() + + +class S + constructor: () -> + @c = () -> + console.log @ + @a = "b" + @prot = arguments.callee.prototype + + s: () -> + console.log @ + @c() + + +s = new S +console.log s.constructor.prototype +#s.c() +#s.s() + +#p = class extends S +#s = new p +#s.c() + +#mix t1, t2 +#t1.my_name() +#console.log t1.prototype +#console.log t2.prototype + +#mix Tester1, Tester2 +#console.log Tester1.prototype + +#t1 = new Tester1 + +#t1.other() + + + + +#b = new Tester false +#b.type 'hiho' + diff --git a/lib/type.coffee b/src/type.coffee similarity index 100% rename from lib/type.coffee rename to src/type.coffee diff --git a/lib/validator.coffee b/src/validator.coffee similarity index 100% rename from lib/validator.coffee rename to src/validator.coffee