Skip to content

Commit

Permalink
Merge pull request #138 from AlexJeng/master
Browse files Browse the repository at this point in the history
Fixed spacing for better consistency
  • Loading branch information
chuanxshi committed Jun 10, 2018
2 parents 72c800b + 138aa98 commit 57975d5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions code-reuse-patterns/prototypal-inheritance.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,33 @@
Person.prototype.getName = function () {
return this.name;
};

// create a new person
var papa = new Person();

// inherit
var kid = object(papa);

// test that both the own property
// and the prototype property were inherited
console.log(kid.getName()); // "Adam"


// parent constructor
function Person() {
// an "own" property
this.name = "Adam";
}

// a property added to the prototype
Person.prototype.getName = function () {
return this.name;
};

// inherit
var kid = object(Person.prototype);
console.log(typeof kid.getName); // "function", because it was in the prototype
console.log(typeof kid.name); // "undefined", because only the prototype was inherited


/* Addition to ECMAScript 5 */
var child = Object.create(parent);

Expand Down

0 comments on commit 57975d5

Please sign in to comment.