Java
by marcelow
JavaScript
function Person(name) {
this.name = name;
}
Person.prototype = {
getName: function() {
return 'Person name:'+this.name;
}
}
function Someone() {
Person.apply(this, arguments);
}
Someone.prototype = Object.create(Person.prototype);
Someone.prototype.constructor = Someone;
Someone.prototype.getName = function() {
return 'Someone name:' + this.name;
}
var p = new Person('rubi');
var s = new Someone('rubi');
console.log(p.getName(), p instanceof Person, p instanceof Someone);
console.log(s.getName(), s instanceof Person, s instanceof Someone);