javascript系列学习----对象相关概念理解

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

本博客的所有博文,大都来自自己的工作实践。希望对大家有用,欢迎大家交流和学习。 我的新站:www.huishougo.com
原文地址:https://www.cnblogs.com/zhouqingda/p/5424921.html