Inheritance/Single: Difference between revisions
m
→{{header|JavaScript}}: 5*s->1
m (→{{header|Java}}: 5*s->1) |
m (→{{header|JavaScript}}: 5*s->1) |
||
Line 998:
=={{header|JavaScript}}==
JavaScript is a class-free, object-oriented language, and as such, it uses prototypal inheritance instead of classical inheritance.
<syntaxhighlight lang="javascript">
function Animal() {
// ...
}
}</syntaxhighlight>▼
// ...
}
Dog.prototype = new Animal();
// ...
}
Cat.prototype = new Animal();
// ...
}
Collie.prototype = new Dog();
// ...
}
Lab.prototype = new Dog();
<syntaxhighlight lang="javascript">Animal.prototype.speak = function() {print("an animal makes a sound")};
|