1、实现选择器,如$('xxid')
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
2、类相关
var Class = {
create: function() {
return function() { this.initialize.apply(this, arguments); }
}
}
分析一下:
1) Class 定义了create函数。并定义了initialize属性。
this.initialize.apply(this,arguments)返回的是函数指针。
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}
var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
var Contains = function(a, b){
return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPosition(b) & 16);
}