一种js构造函数的写法
来源:互联网 发布:按键精灵自瞄源码 编辑:程序博客网 时间:2024/05/16 12:26
mootools 1.2b1有了很大的变化,其中,把构造函数简化一下是这么写的:
看看这是怎么回事:
new Hash的时候获得的实际是个new Native出来的对象。
new Native会执行这句代码:options.initalize;
很难懂,但这种做法在JS里面非常普遍,值得注意。
var Native = function(options){
var object = options.initialize;
return object;
};
var Hash = new Native({
initialize: function(object){
console.log(object);
for (var key in object){
if (!this[key]) this[key] = object[key];
}
return this;
}
});
var hash = new Hash({abc:123,def:456});
var object = options.initialize;
return object;
};
var Hash = new Native({
initialize: function(object){
console.log(object);
for (var key in object){
if (!this[key]) this[key] = object[key];
}
return this;
}
});
var hash = new Hash({abc:123,def:456});
new Hash的时候获得的实际是个new Native出来的对象。
new Native会执行这句代码:options.initalize;
很难懂,但这种做法在JS里面非常普遍,值得注意。
- 一种js构造函数的写法
- js构造函数写法
- index.js 一种js的写法模式
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS的构造函数
- JS函数的写法总结
- JS函数的规范写法
- JS 匿名函数的写法
- js函数的多种写法
- 多个构造函数的写法
- 一般----派生类构造函数的写法
- linux进程之fork vs vfork
- 无法打开Web项目.......
- 工厂方法模式 Factory Method Pattern
- T-SQL 删除重复的记录
- oracle create job
- 一种js构造函数的写法
- log4j 好文
- win2003服务器安全设置技术实例(一)
- 在网页里添加Web Live Messenger对话框
- 判断输入的数是个几进制数
- 开发ERP、MIS、CRM等网络业务系统,竟然可以这样做?!
- linux下字符集编码转换轻松实现
- About Attitude is everything(Lovegirl = 100)---嘟嘟胖
- 最近有点懒