码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-04-23 17:58:47      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/zhouqingda/p/5424921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!