Cannot set property 'name' of undefined JS

This question already has an answer here:

  • How does JavaScript .prototype work? 21 answers

  • Objects don't have a prototype property (unless you create one). You usually only assign to the prototype property of constructors:

    function Person(firstname, lastname) {
      this.firstname = firstname;
      this.lastname = lastname;
    }
    
    Person.prototype.name = 'Toby';
    
    var A = new Person('John', 'Doe');
    
    // A.name === 'Toby';
    
    链接地址: http://www.djcxy.com/p/30068.html

    上一篇: 在JavaScript中使用prototype属性有什么用?

    下一篇: 无法设置未定义JS的属性“名称”