1、构造函数(相对于面向对象编程语言里面的类)
2、对象实例(它是由构造函数构造出来的对象,使用到关键字 new)
3、this关键字(往往是指我们的对象本身)
下面我们来看一个实例:
var Person = function Person(living, age, gender) {
// "this" below is the new object that is being created (i.e. this = new Object();)
this.living = living;
this.age = age;
this.gender = gender;
this.getGender = function() {return this.gender;};
}
// when the function is called with the new keyword "this" is returned instead of false
// instantiate a Person object named cody
var cody = new Person(true, 33, 'male');
// cody is an object and an instance of Person()
console.log(typeof cody); // logs object
console.log(cody); // logs the internal properties and values of cody
console.log(cody.constructor); // logs the Person() function