我在理解此操作时遇到问题:
tmp.setAttribute(i, prop[i]);
在这个for循环中经过。prop-array 如何创建 2 个参数。据我了解var = i
只是一个变量,对吗?但显然它就像那样成为方法中的 1:st 参数?
谢谢你的时间。
http://jsbin.com/ozoqob/2/edit
var MYAPP = MYAPP || {};
MYAPP.dom = {};
MYAPP.dom.Element = function(type, prop){
var tmp = document.createElement(type);
for (var i in prop) {
tmp.setAttribute(i, prop[i]);
/*
WHAT I DONT UNDERSTAND IS HOW THIS FOR-LOOP DIVIDE THE ARRAY IN TWO ARGUMENTS?? BEACAUSE 'I' IS JUST A VARIABLE WHICH IS USED TO LOOP THRU THE ARRAY BUT APPARENTLY NOT RIGHT?
*/
console.log(i); // how? is this arguments divided?
console.log(prop[i]);
}
return tmp;
};
var el1 = new MYAPP.dom.Element(
'a',
{href:'http://phpied.com'}
);
console.log(el1);