<script type="text/javascript">
var Parent =function(){
this.x=100;
}
var Child =function(){
this.y=200;
}
Parent.prototype.getX = function getX(){
return this.x;
};
Child.prototype = new Parent();
Child.prototype.getY = function getY(){
return this.y;
}
var c1 =new Child();
console.log(c1)
var Parent =function(){
this.x=100;
};
var Child =function(){
Parent.call(this);
this.y=200;
};
Parent.prototype.getX = function getX(){
return this.x;
};
Child.prototype.getY = function getY(){
return this.y;
}
var c1 =new Child;
console.log(c1)
var Parent =function(){
this.x=100;
};
var Child =function(){
Parent.call(this);
this.y=200;
};
Parent.prototype.getX = function getX(){
return this.x;
};
Child.prototype.__proto__ = Parent.prototype;
Child.prototype.getY = function getY(){
return this.y;
}
var c1 =new Child;
console.log(c1)
var Parent =function(){
this.x=100;
};
var Child =function(){
Parent.call(this);
this.y=200;
};
Parent.prototype.getX = function getX(){
return this.x;
};
Child.prototype = Object.create(Parent.prototype);
Child.prototype.getY = function getY(){
return this.y;
}
var c1 =new Child;
console.log(c1)
class Parent{
constructor() {
this.x=100;
}
getX(){
return this.x;
};
}
class Child extends Parent{
constructor() {
super()
this.y=200;
}
getY(){
return this.y;
};
}
var c1 =new Child;
console.log(c1)
</script>
function Foo(){
getName=function(){
alert(1);};
return this;
}
Foo.getName = function(){
alert(2);}
Foo.prototype.getName = function(){
alert(3);
}
var getName = function(){
alert(4);
}
function getName(){
alert(5);
}
Foo.getName();
getName();
Foo().getName();
getName();
new Foo.getName();
new Foo().getName();