您的位置:首页 > Web前端 > JavaScript

【记录】这样在网页里构造JS 更加容易理解

2010-03-17 11:27 246 查看
// Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}

var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}

var aa=Class.create();
aa.prototype={

initialize:function(options){
this.SetOptions(options);
},

SetOptions: function(options) {

this.options = {//默认值
xxx: 0,//最小值
};

Object.extend(this.options, options || {});
},

show:function(){
alert(this.options.xxx)
}
}

var cc=new aa({xxx:100})

var bb=function(o){
this.options={xxx:0};
Object.extend(this.options, o || {});
}

bb.prototype={
show:function(){
alert(this.options.xxx)
}
}

var dd=new bb({xxx:100})
// ]]>
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}

var bb=function(o){
this.options={xxx:0};
Object.extend(this.options, o || {});
}

bb.prototype={
show:function(){
alert(this.options.xxx)
}
}

var dd=new bb({xxx:100})
dd.show()


[/code]
运行以上代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐