版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32279193/article/details/78257754
function Person(first,last,age,gender,interests){
this.name = {
first,
last
};
this.age = age;
this.gender = gender;
this.interests = interests;
this.bio = function(){
alert(this.name.first + ' ' + this.name.last + 'is' +this.age)
};
this.greeting = function(){
alert('Hi! I\'m' + this.name.first + '.');
};
}
创建对象实例:
var person1 = new Person('xiang','xing',22,'male',['music', 'skiing']);
访问属性方法:
person1['age']
person1.interests[1]
person1.bio()