Base.js
来源:互联网 发布:淘宝买狗本地的可靠吗 编辑:程序博客网 时间:2024/05/16 10:46
Base.js部分代码还不理解,作个记号!
/*Base.jsversion 1.1Copyright 2006-2010License:...*/var Base = function(){};Base.extend = function(_instance,_static){//subclassvar extend = Base.prototype.extend;//build thid prototypeBase._prototyping = true;var proto = new this;extend.call(proto,_instance);proto.base = function(){//call this method from any other method to invoke that method's ancestor}delete Base._prototyping;//create the wrapper for the constructor functionvar constructor = proto.constructor;var klass = proto.constructor = function(){if(!Base._prototyping){if(this._constructing || this.constructor == klass){this._constructing = true;constructor.apply(this,arguments);delete this._constructing;}else if (arguments[0] != null){return (arguments[0].extend || extend).call(arguments[0],proto);}}};//build the clas interface klass.ancestor = this;klass.extend = this.extend;klass.forEach = this.forEach;klass.implement = this.implement;klass.prototype = proto;klass.toString = this.toString;klass.valueOf = function(type){//return (type == "object")?klass:constructor;return (type == "object")?klass:constructor.valueOf();};extend.call(klass,_static);//class initialisationif(typeof klass.init == "function"){klass.init();}return klass;};Base.prototype = {extend:function(source,value){if(arguments.length>1){var ancestor = this[source];if(ancestor && (typeof value == "function") && (!ancestor.valueOf || ancestor.valueOf() != value.valueOf())&& /\bbase\b/.test(value)){var method = value.valueOf();value = function(){var previors = this.vase || Base.prototype.base;this.base = ancestor;var returnValue = method.apply(this,arguments);this.base = previous;return returnValue;};value.toString = Base.toString;}this[source] = value;}else if(source){//extending with an object literalvar extend = Base.prototype.extend;if(!Base._prototyping && typeof this != "function"){extend = this.extend || extend;}var proto = {toSource:null};//do the "toString" and other methods manuallyvar hidden = ["constructor","toString","valueOf"];// if we are prototyping then include the constructorvar i = Base._prototyping ?0:1;whild(key = hidden[i++]){if(source[key] != proto[key]){extend.call(this,key,source[key]);}}for(var key in source){if(!proto[key]){extend.call(this,key,source[key]);}}}return this;}};//initialiseBase = Base.extend({constructor:function(){this.extend(arguments[0]);}},{ancestor:Object,verson:"1.1",forEach:function(object,block,context){for(var key in object){if(this.prototype[key] === undefined){block.call(context,object[key],key,object);}}},implement:function(){for(var i=0;i<arguments.length;i++){if(typeof arguments[i] == "function"){//if it's a function,call itarguments[i](this.prototype);}else{//add the interface using the extend methodthis.prototype.extend(arguments[i]);}}return this;},toString:function(){return String(this.valueOf());}});
使用:
var Person = Base.extend({constructor:function(name){this.name = name;},getName:function(){return this.name;}});var User = Person.extend({constructor:function(name,password){this.base(name);this.password = password;},getPassword:function(){return this.password;}});var user = new User("xuyi","12345");alert(user.getName()+', '+user.getPassword());
- Base.js
- base.js
- Base.js
- base.js文件
- JS中的Base库
- 时间方法 base.js
- vue webpack.base.config.js
- 页面使用base标签与JS冲突
- 一个看不明白的base.js
- Javascript之base.js原型那些事儿
- javascript手势操作插件 base-gesture.js
- base
- Base
- BASE
- base-``
- base
- Base
- base
- vxworks中断
- struct hibernate spring 经典框架 搭建 入门实例
- JAVA Web.xml 加载顺序
- 利用itext 生成pdf 文件---cell 跨页问题
- win7时代,好玩
- Base.js
- Intel设1亿美元基金推动跨平台应用开发
- Linux中断调试日志
- 反编译Android apk文件
- linq 查询学习笔记
- nginx subrequest的实现解析
- XDOJ_1001解题报告
- php setcookie 之 Cannot modify header information 解决方法
- 基于Android的Linux内核的电源管理:Early Suspend