What does 'is an instance of' mean in Javascript?

后端 未结 7 799
面向向阳花
面向向阳花 2020-12-18 00:42

The answer to this question: What is the initial value of a JavaScript function's prototype property?

has this sentence:

The initial value

7条回答
  •  醉酒成梦
    2020-12-18 01:09

    JavaScript does not have classes, but it does have Types. You can define your own type and create a new instance using the new keyword:

    function Foo(initialValue) {
        this.value = initialValue || 0;
    }
    var foo = new Foo(17);
    var fooIsAFoo = foo instanceof Foo;  // true!
    var fooIsAnObject = foo instanceof Object; // also true!  We have inheritance here :)
    

提交回复
热议问题