【记录】这样在网页里构造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})
// ]]>
[/code]
运行以上代码
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]
运行以上代码
相关文章推荐
- 微信网页开发weixin://preInjectJSBridge/fail、分享描述失效问题记录
- 带你理解 JS 容易出错的坑和细节
- JS清除网页历史记录,屏蔽后退按钮
- js实现贪吃蛇小游戏(容易理解)
- JS--我发现,原来你是这样的JS:面向对象编程OOP[1]--(理解对象和对象属性类型)
- 通过Jquery.cookie.js实现展示浏览网页的历史记录超管用
- CMake常见指令总结,修改的更加容易理解
- 关于js与css加载的理解,理解网页head标签中的JS和CSS,哪种文件放在前面,哪种放在后面比较好
- 记录下js控制网页WMP播放的属性
- 使用PM2将Node.js的集群变得更加容易
- 数据抓取中post与get方式的处理深入理解(不用给网页标签赋值也不用模拟提交js)
- JS新手学习记录贴-JS运行机制初理解
- 微信公共服务平台开发(.Net 的实现)12-------网页授权(上 :更加深入理解OAuth2.0 )
- 使用js在网页上记录鼠标划圈的小程序
- 使用js在网页上记录鼠标划圈的小程序
- 详解如何使用PM2将Node.js的集群变得更加容易
- js组件中那些晦涩难懂的写法,理解这个以后看组件会容易很多,包括JQ源码
- 微信公共服务平台开发(.Net 的实现)12-------网页授权(上 :更加深入理解OAuth2.0 )
- 分享一段JS代码,个人感觉很使用:网页浏览历史记录
- 微信公共服务平台开发(.Net 的实现)12-------网页授权(上 :更加深入理解OAuth2.0 )