javascript USES prototype for single inheritance

  • 2020-05-09 18:08:47
  • OfStack

1. Use prototype for single inheritance.

// define 1 a A class
function A(){
// for A Class calls properties dynamically color, With the method sayColor
A.prototype.color = "blue";
A.prototype.sayColor = function(){
// To create the 1 a B class
function B(){
// let B Inherited from A
B.prototype=new A(); //new Out of the A Is assigned to B The prototype, B Is included in A All the properties and methods defined in .
// Can I inherit it sayColor rewrite .
alert(" rewrite ");
var b=new B();

Related articles: