Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. let a = Object.create(null); // doesn't have a prototype
  2. let b = { }; // has Object.prototype
  3.  
  4. var User = function(name) {
  5. this.name = name;
  6. /* jshint proto: true */
  7. this.__proto__ = b;
  8. // User.prototype.constructor = User // This constructor creates automatically,
  9. // but it could be easyly overriden with User.prototype = {}
  10. };
  11.  
  12. // This approach doesn't override default prototype's constructor property
  13. User.prototype.hello = function(who) {
  14. console.log("Hello, " + who.name);
  15. };
  16.  
  17. var vasya = new User("Вася"); // Has __proto__ = User.prototype
  18. var petya = new User("Петя");
  19. petya.hit = () => "Hit";
  20.  
  21.  
  22. vasya.hello(petya);
  23. console.log(petya.hit());
  24. console.log(Object.getPrototypeOf(petya));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement