例1,js基本类代码:
复制代码 代码示例:
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments); }
}
};
例2,对象扩展:
复制代码 代码示例:
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
};
例3,获取DOM元素属性:
复制代码 代码示例:
var Attr = function (element, key, value) {
if(arguments.length == 2){
if(element.getAttribute){
return element.getAttribute(key) || element[key] || undefined;
}
}
else if(arguments.length == 3){
element.setAttribute(key,value);
}
};