Javascript:`new a()`vs`a()` - new operator vs functioncall()

时间:2016-02-23 10:10:20

标签: javascript object properties console new-operator

function a() {
    this.a = function () {
        console.log("In A");
    }
    this.b = function () {
        console.log("In B");
    }
    this.c = function (cb) {
        console.log("In C ");
    }
    this.d = function (cb) {
        cb();
        console.log("In D");
    }

    this.d(function () {
        this.a();
        this.b();
        this.c();
    });
}    
  1. var A = a();
  2. IN A
    IN B
    IN C
    IN D

    1. var A = new a();
    2. IN A
      IN B
      IN C
      IN D
      IN B
      IN C
      IN D

      有人能解释一下这是如何运作的吗?

      此外,有关链接的任何建议,我可以找到这些有趣的问题/问题?

      提前谢谢:)

0 个答案:

没有答案