zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    bzoj4513: [Sdoi2016]储能表
    bzoj4000: [TJOI2015]棋盘
    bzoj3067: Hyperdrome
    bzoj4943: [Noi2017]蚯蚓
    bzoj4044: [Cerc2014] Virus synthesis
    bzoj3676: [Apio2014]回文串
    bzoj4543: [POI2014]Hotel加强版
    bzoj1921: [Ctsc2010]珠宝商
    bzoj4754: [Jsoi2016]独特的树叶
    作图的配色
  • 原文地址:https://www.cnblogs.com/zhouqingda/p/5424921.html
Copyright © 2011-2022 走看看