<script type="text/javascript">
var Class = {
//创建类
create : function () {
return function () {
this.initialize.apply(this, arguments);
};
}
};var $A = function (a) {
//转换数组
return a ? Array.apply(null, a) : new Array;
};var $ = function (id) {
//获取对象
return document.getElementById(id);
};var Try = {
//检测异常
these : function () {
var returnValue, arg = arguments, lambda, i;
for (i = 0 ; i < arg.length ; i ++) {
lambda = arg[i];
try {
returnValue = lambda();
break;
} catch (exp) {}
}
return returnValue;
}
};Object.extend = function (a, b) {
//追加方法
for (var i in b) a[i] = b[i];
return a;
};Object.extend(Object, { addEvent : function (a, b, c, d) {
//添加函数
if (a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
return c;
},
delEvent : function (a, b, c, d) {
if (a.detachEvent) a.detachEvent(b[0], c);
else a.removeEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
return c;
},
reEvent : function () {
//获取Event
return window.event ? window.event : (function (o) {
do {
o = o.caller;
} while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0]));
return o.arguments[0];
})(this.reEvent);
}
});Function.prototype.bind = function () {
//绑定事件
var wc = this, a = $A(arguments), o = a.shift();
return function () {
wc.apply(o, a.concat($A(arguments)));
};
};var CDrag = Class.create();CDrag.IE = /MSIE/.test(window.navigator.userAgent);CDrag.load = function (obj_string, func, time) {
//加载对象
var index = 0, timer = window.setInterval(function () {
try {
if (eval(obj_string + ".loaded")) {
window.clearInterval(timer);
func(eval("new " + obj_string));
}
} catch (exp) {} if (++ index == 20) window.clearInterval(timer);
}, time + index * 3);
};CDrag.database = {
//数据存储
json : null,
parse : function (id) {
//查找资源
var wc = this, json = wc.json, i;
for (i in json) {
if (json[i].id == id)
return json[i];
}
}
};CDrag.Ajax = Class.create();Object.extend(CDrag.Ajax, { getTransport: function() {
return Try.these(
function () { return new ActiveXObject('Msxml2.XMLHTTP') },
function () { return new ActiveXObject('Microsoft.XMLHTTP') },
function () { return new XMLHttpRequest() }
) || false;
}
});CDrag.Ajax.prototype = { initialize : function (url) {
//初始化
var wc = this;
wc.ajax = CDrag.Ajax.getTransport();
},
load : function (func) {
var wc = this, ajax = wc.ajax;
if (ajax.readyState == 4 && ajax.status == 200)
func(ajax.responseText);
},
send : function (url, func) {
var wc = this, ajax = wc.ajax,
querys = url + "&" + new Date().getTime() + (10000 + parseInt(Math.random() * 10000));
ajax.open("get", querys, true);
ajax.onreadystatechange = wc.load.bind(wc, func);
ajax.send(null);
}
};CDrag.Table = Class.create();CDrag.Table.prototype = {
//列的拖拽暂时不考虑 initialize : function () {
//初始化
var wc = this;
wc.items = []; //创建列组
},
add : function () {
//添加列
var wc = this, id = wc.items.length, arg = arguments;
return wc.items[id] = new CDrag.Table.Cols(id, wc, arg[0]);
}
};CDrag.Table.Cols = Class.create();CDrag.Table.Cols.prototype = {
initialize : function (id, parent, element) {
//初始化
var wc = this;
wc.items = []; //创建列组
wc.id = id;
wc.parent = parent;
wc.element = element;
},
add : function () {
//添加行
var wc = this, id = wc.items.length, arg = arguments;
return wc.items[id] = new CDrag.Table.Rows(id, wc, arg[0], arg[1], arg[2]);
},
ins : function (num, row) {
//插入行
var wc = this, items = wc.items, i;
if (row.parent == wc && row.id < num) num --; //同列向下移动的时候
for (i = num ; i < items.length ; i ++) items[i].id ++;
items.splice(num, 0, row);
row.id = num, row.parent = wc;
return row;
},
del : function (num) {
//删除行
var wc = this, items = wc.items, i;
if (num >= items.length) return;
for (i = num + 1; i < items.length ; i ++) items[i].id = i - 1;
return items.splice(num, 1)[0];
}
};CDrag.Table.Rows = Class.create();
</script>比如“create : function () ”
这好像是在一个变量内部定义的
这是什么意思?这种是什么用法?能否给出解释和示例?
谢谢回答!!
var Class = {
//创建类
create : function () {
return function () {
this.initialize.apply(this, arguments);
};
}
};var $A = function (a) {
//转换数组
return a ? Array.apply(null, a) : new Array;
};var $ = function (id) {
//获取对象
return document.getElementById(id);
};var Try = {
//检测异常
these : function () {
var returnValue, arg = arguments, lambda, i;
for (i = 0 ; i < arg.length ; i ++) {
lambda = arg[i];
try {
returnValue = lambda();
break;
} catch (exp) {}
}
return returnValue;
}
};Object.extend = function (a, b) {
//追加方法
for (var i in b) a[i] = b[i];
return a;
};Object.extend(Object, { addEvent : function (a, b, c, d) {
//添加函数
if (a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
return c;
},
delEvent : function (a, b, c, d) {
if (a.detachEvent) a.detachEvent(b[0], c);
else a.removeEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
return c;
},
reEvent : function () {
//获取Event
return window.event ? window.event : (function (o) {
do {
o = o.caller;
} while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0]));
return o.arguments[0];
})(this.reEvent);
}
});Function.prototype.bind = function () {
//绑定事件
var wc = this, a = $A(arguments), o = a.shift();
return function () {
wc.apply(o, a.concat($A(arguments)));
};
};var CDrag = Class.create();CDrag.IE = /MSIE/.test(window.navigator.userAgent);CDrag.load = function (obj_string, func, time) {
//加载对象
var index = 0, timer = window.setInterval(function () {
try {
if (eval(obj_string + ".loaded")) {
window.clearInterval(timer);
func(eval("new " + obj_string));
}
} catch (exp) {} if (++ index == 20) window.clearInterval(timer);
}, time + index * 3);
};CDrag.database = {
//数据存储
json : null,
parse : function (id) {
//查找资源
var wc = this, json = wc.json, i;
for (i in json) {
if (json[i].id == id)
return json[i];
}
}
};CDrag.Ajax = Class.create();Object.extend(CDrag.Ajax, { getTransport: function() {
return Try.these(
function () { return new ActiveXObject('Msxml2.XMLHTTP') },
function () { return new ActiveXObject('Microsoft.XMLHTTP') },
function () { return new XMLHttpRequest() }
) || false;
}
});CDrag.Ajax.prototype = { initialize : function (url) {
//初始化
var wc = this;
wc.ajax = CDrag.Ajax.getTransport();
},
load : function (func) {
var wc = this, ajax = wc.ajax;
if (ajax.readyState == 4 && ajax.status == 200)
func(ajax.responseText);
},
send : function (url, func) {
var wc = this, ajax = wc.ajax,
querys = url + "&" + new Date().getTime() + (10000 + parseInt(Math.random() * 10000));
ajax.open("get", querys, true);
ajax.onreadystatechange = wc.load.bind(wc, func);
ajax.send(null);
}
};CDrag.Table = Class.create();CDrag.Table.prototype = {
//列的拖拽暂时不考虑 initialize : function () {
//初始化
var wc = this;
wc.items = []; //创建列组
},
add : function () {
//添加列
var wc = this, id = wc.items.length, arg = arguments;
return wc.items[id] = new CDrag.Table.Cols(id, wc, arg[0]);
}
};CDrag.Table.Cols = Class.create();CDrag.Table.Cols.prototype = {
initialize : function (id, parent, element) {
//初始化
var wc = this;
wc.items = []; //创建列组
wc.id = id;
wc.parent = parent;
wc.element = element;
},
add : function () {
//添加行
var wc = this, id = wc.items.length, arg = arguments;
return wc.items[id] = new CDrag.Table.Rows(id, wc, arg[0], arg[1], arg[2]);
},
ins : function (num, row) {
//插入行
var wc = this, items = wc.items, i;
if (row.parent == wc && row.id < num) num --; //同列向下移动的时候
for (i = num ; i < items.length ; i ++) items[i].id ++;
items.splice(num, 0, row);
row.id = num, row.parent = wc;
return row;
},
del : function (num) {
//删除行
var wc = this, items = wc.items, i;
if (num >= items.length) return;
for (i = num + 1; i < items.length ; i ++) items[i].id = i - 1;
return items.splice(num, 1)[0];
}
};CDrag.Table.Rows = Class.create();
</script>比如“create : function () ”
这好像是在一个变量内部定义的
这是什么意思?这种是什么用法?能否给出解释和示例?
谢谢回答!!
解决方案 »
- js读取数组的问题
- JSP页面中 new ActiveXObject("WScript.Shell") 无法运行的问题
- 关于 EXT JS grid不显示header
- text的onchange变化触发select的变化,和数据库相连
- 请高手指点--如何让图片飘浮在flash上
- 求一个textbox输入限定长度问题的解法。
- 可以关闭"可以关闭IE中的进度条吗"吗?
- 问:用window.close(),怎能才不弹出确认对话框?
- [extjs日历组件Extensible]大神请进,急!!!在线等!!!
- promise有些还是不太了解,希望有大神能帮看看
- 匹配url的正则
- JS 操作 DOM 的问题!
2 {属性:值}的方式相当于 对象.属性 = 值
a = {x:'12'} 等于 var a = new Object(); a.x = 12;
b = {create:function(){}} 相当于 var b = new Object(); b.create = function(){}