美文网首页
2019-03-19约定

2019-03-19约定

作者: 泡沫双鱼座 | 来源:发表于2019-03-19 17:16 被阅读0次

构造函数的首字母大写,行业约定,它是构造函数,要用new来调用。

var Person = function(name,pwd){

//对this的理解,分下面三步=====>下面用new来调用这个函数,所有1和3省略,保留2就可以了

//1.创建一个空对象,用this来引用

//var this = {};

//2.将用户自定义的属性和方法(name,pwd,getInfo)添加到这个用this引用的新对象上面

    this.name = name;

    this.pwd = pwd;

    this.getInfo = function(){

    return this.name + "的密码是:" + this.pwd}

//3.返回这个新对象this

//return this;

}

//构造函数是用来生成对象

var person1 = new Person('admin','123562');

相关文章

网友评论

      本文标题:2019-03-19约定

      本文链接:https://www.haomeiwen.com/subject/uisnmqtx.html