快捷导航

亲们,为什么set方法里面不能用this.name,而必须用name;this是实例化的对

function student(name,sex,age){                        var privateStore={                                name:"张宇",                                sex:"男",                                age:"18"                        };                        function _set(){                                privateStore.name=this.name;                                privateStore.sex=this.sex;                                privateStore.age=this.age;                        }                        function _get(){                                return '姓名:'+privateStore.name+', 性别:'+privateStore.sex+', 年龄:'+privateStore.age+'
';                        }                        this.get=function(){                                return _get;                        }                        this.set=function(){                                return _set;                        }                }                var s1=new student('xh','female','19');                document.write(s1.get()());                s1.set()();                document.write(s1.get()());

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

你这是没明白this的意思。建议先去搜索了解下JS中的this,这很重要
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP