| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 916 人关注过本帖
标题:求助,急~~ 谢谢!
取消只看楼主 加入收藏
国际在线
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-8-27
结帖率:100%
收藏
 问题点数:0 回复次数:1 
求助,急~~ 谢谢!
<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");的时候就出错了。说是对象不支持此方法。
搜索更多相关主题的帖子: previously function property through 
2008-08-27 13:01
国际在线
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-8-27
收藏
得分:0 
嗯,好的,谢谢渚薰GG的热心帮忙。
2008-08-27 18:22
快速回复:求助,急~~ 谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016480 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved