求助,急~~ 谢谢!
<html><script>
// Create a new user object that accepts an object of properties
function User(properties){
// Iterate through the properties of the object, and make sure
// that it's propperly 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;
};
})();}
}
alert(1);
// Create a new user object instance and pass in an object of
// properties to seed it with
var user= new User({
name:"Bob",
age:44
});
// Just note that the name property does not exist, as it's private
// within ther properties object
alert(user.name==null);
// However, we're able to access its value using the new getname()
// method, that was dynamically generated
alert(user.getname()=="Bob");
// Finally, we can see that it's possible to set and get the age using
// the newly generated functions
user.setage(22);
alert(user.getage==22);
</script>
</html>
这是一段测试privilleged 方法的javascript 代码,运行到alert(user.getname()=="Bob");的时候就出错了。说是对象不支持此方法。