zoukankan      html  css  js  c++  java
  • new operator

    new operator

      When the code new Foo(...) is executed, the following things happen:

    1. A new object is created, inheriting from Foo.prototype.(即新建对象的 __prototype__ 属性与 Foo.prototype 一样)
    2. The constructor function Foo is called with the specified arguments and this bound to the newly created object. new Foo is equivalent to new Foo(), i.e. if no argument list is specified, Foo is called without arguments.
    3. The object returned by the constructor function becomes the result of the wholenew expression. If the constructor function doesn't explicitly return an object, the object created in step 1 is used instead. (Normally constructors don't return a value, but they can choose to do so if they want to override the normal object creation process.)

      You can add a shared property to a previously defined object type by using theFunction.prototype property. This defines a property that is shared by all objects created with that function, rather than by just one instance of the object type. The following code adds a color property with value null to all objects of type car, and then overwrites that value with the string "black" only in the instance object car1

      

    Function

      Function objects inherit from Function.prototype.  Function.prototype cannot be modified. In JavaScript every function is actually a Function object.

      prototype和__proto__是完全不一样的两个东西。

      

      __proto__用于实现继承。

      

      

      

  • 相关阅读:
    synchronized锁机制 之 代码块锁(转)
    执行mvn 报错 source-1.5 中不支持 diamond运算符
    Git常用命令及场景
    mysql数据库导入与导出
    Linux磁盘空间分析及清理(df、du、rm)
    IIs配置文件存放路径
    解决SQLite database is locked
    C#测试web服务是否可用
    Jquery easyui-combobox 的一个BUG
    iframe自适应方法
  • 原文地址:https://www.cnblogs.com/tekkaman/p/5212891.html
Copyright © 2011-2022 走看看