stormbytes

Untitled

Jun 30th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // example using constructor function
  2.  
  3. function Person (name, age) {
  4.    this.name = name;
  5.    this.age = age;
  6. }
  7.  
  8. Person.prototype.greet = function () {
  9.    console.log('Hello, I\'m ' + this.name)
  10. }
  11.  
  12. var man = new Person("dude", 23);
  13.  
  14.  
  15.  
  16.  
  17. // example using obj literal as prototype
  18.  
  19. var Human = {
  20.    name: null,
  21.    age: null,
  22.    location: null
  23. }
  24.  
  25. Human.greet = function () {
  26.    console.log("Hello, I'm " + this.name)
  27. }
  28.  
  29. var woman = Object.create(Human)
Advertisement
Add Comment
Please, Sign In to add comment