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
  • 相关阅读:
    Java类加载器总结
    Java程序编译和运行的过程
    Spring+Struts2+Hibernate整合
    Spring+MyBatis+SpringMVC整合
    声明式事务管理
    Scala sbt 添加国内镜像
    持续天数算法
    idea run shell set user name
    java insert mysql 中文乱码
    Samba服务器 安装
  • 原文地址:https://www.cnblogs.com/zhouqingda/p/5424921.html
Copyright © 2011-2022 走看看