function User( properties ) {
// Iterate through the properties of the object, and make sure
// that it's properly scoped (as discussed previously)
for ( var i in properties ) { (function(){
// Create a new getter for the property
this[ "get" + i ] = function() {
return properties[i];
};
// Create a new setter for the property
this[ "set" + i ] = function(val) {
properties[i] = val;
};
})(); }
}
其中this[ "get" + i ] = function() {
return properties[i];
};
那个this["get" + i ]是什么语法,有什么意义?求教
// Iterate through the properties of the object, and make sure
// that it's properly scoped (as discussed previously)
for ( var i in properties ) { (function(){
// Create a new getter for the property
this[ "get" + i ] = function() {
return properties[i];
};
// Create a new setter for the property
this[ "set" + i ] = function(val) {
properties[i] = val;
};
})(); }
}
其中this[ "get" + i ] = function() {
return properties[i];
};
那个this["get" + i ]是什么语法,有什么意义?求教
document["title"] = "zswang 路过";
//等价:document.title = "zswang 路过"属性名可以是任意字符串
访问document.1就错了
但可以访问document["1"]