Object vs Class vs Function

后端 未结 7 1019
南方客
南方客 2020-11-28 20:03

I was wondering - what\'s the difference between JavaScript objects, classes and functions? Am I right in thinking that classes and functions are types of objects?

A

7条回答
  •  失恋的感觉
    2020-11-28 20:29

    Update 2015

    There are classes in javascript they just aren't used on older browsers.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

    It has constructors, extentions, and the like.

    class Cat { 
      constructor(name) {
        this.name = name;
      }
      
      speak() {
        console.log(this.name + ' makes a noise.');
      }
    }
    
    class Lion extends Cat {
      speak() {
        super.speak();
        console.log(this.name + ' roars.');
      }
    }
    

提交回复
热议问题