关于面向对象问题
JS能实现多态吗?怎么实现?用什么方法?
JS能实现多态吗?怎么实现?用什么方法?
2014-12-25
function Person() {
this.hi = function(){}
}
function One() {}
One.prototype = new People();
One.prototype.hi = function() {
return "This is one"
}
function Two() {}
Two.prototype = new People();
Two.prototype.hi = function() {
return "This is two"
}
var o = new One();
if(o instanceof People) {
alert("hihi, o from People")
}
举报