// ES6
class Person{
    constructor(name, age){
        this.name = name;
        this.age = age;
    }
    getName(){
        console.log(this.name)
    }
}
p = new Person('alex', 34);
p.getName();


// ES5
function Person(name){
        this.name = name;
        this.getName = function(){
        console.log(this.name)
    }
}
var p = new Person('tom');
p.getName();


//ES5
var person = {
    name: 'tom',
    getName: function(){
        console.log(this.name);
    }
}
person.getName();

 

相关文章:

  • 2021-11-13
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
相关资源
相似解决方案