I am currently transforming from Java
to Javascript
, and it's a bit hard for me to figure out how to extend objects the way I want it to do.
I've seen several people on the internet use a method called extend on object. The code will look like this:
var Person = {
name : 'Blank',
age : 22
}
var Robot = Person.extend({
name : 'Robo',
age : 4
)}
var robot = new Robot();
alert(robot.name); //Should return 'Robo'
Does anyone know how to make this work?
I've heard that you need to write
Object.prototype.extend = function(...);
But I don't know how to make this system work. If it is not possible, please show me another alternative that extends an object.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…