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

后端 未结 7 811
面向向阳花
面向向阳花 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:19

    In JavaScript functions are first-class objects, that means you can treat them just like any object.

    //Define class

       function User(name,age)
        {
            this.Name=name;
            this.Age=age
        }
    

    //create insatnces

    var user1= new User('Demo1','50');
    var user2= new User('Demo2','100');
    
    
    alert(user1.Name);
    alert(user2.Name);
    

    http://jsfiddle.net/praveen_prasad/hmUku/

    http://en.wikipedia.org/wiki/First-class_function

提交回复
热议问题