JS-10-객체-ES6
Class by ES5
'use strict';
function User(name){
this.name = name;
}
User.prototype = {
constructor: User,
say: function() {
return 'My name is ' + this.name;
}
}
function Admin(name) {
User.apply(this, arguments);
}
Admin.prototype = Object.create(User.prototype);
Admin.prototype.constructor = Admin;
Admin.prototype.say = function(){
var superClassPrototype = Object.getPrototypeOf(this.constructor.prototype);
return '[Admin] ' + superClassPrototype.say.call(this);
}
var user = new User('Hoil');
console.log(user.say()); // My name is Hoil
var admin = new Admin('Tmon');
console.log(admin.say()); // [Administrator] My name is HoilClass by ES6
Last updated
Was this helpful?