javascript package
收集各种实现中!http://blog.nyarla.net/2006/11/28/1
var package = function ( className, CodeBlock ) { var classes = className.split('.'), class = new String, obj; for ( var i = 0, len = classes.length; i < len; i++ ) { if ( i > 0 ) { class += '.' } class += classes[i]; var evalCode = "if(typeof(" + class + ")=='undefined'){" + class + "={}}"; ( i == len - 1 ) ? obj = eval( evalCode ) : eval( evalCode ) ; } if ( typeof(CodeBlock) == 'function' ) { CodeBlock.call(obj); } return obj; }
package('foo'); package('foo.bar', function () { var self = this; self.say = function () { return alert('Javascript package!!'); } });
机器瞎学/数据掩埋/模式混淆/人工智障/深度遗忘/神经掉线/计算机幻觉/专注单身二十五年