Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let a = Object.create(null); // doesn't have a prototype
- let b = { }; // has Object.prototype
- var User = function(name) {
- this.name = name;
- /* jshint proto: true */
- this.__proto__ = b;
- // User.prototype.constructor = User // This constructor creates automatically,
- // but it could be easyly overriden with User.prototype = {}
- };
- // This approach doesn't override default prototype's constructor property
- User.prototype.hello = function(who) {
- console.log("Hello, " + who.name);
- };
- var vasya = new User("Вася"); // Has __proto__ = User.prototype
- var petya = new User("Петя");
- petya.hit = () => "Hit";
- vasya.hello(petya);
- console.log(petya.hit());
- console.log(Object.getPrototypeOf(petya));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement