我想用我的父函数有一个值。这可能是一个愚蠢的问题,但我一直无法找到如何做到这一点的直接教程。使用原型在Javascript中继承
我知道,在使用原型有可能
function handler (selector) {
return selector;
}
Object.prototype.alertLine = function() {
alert(this);}
handler('hello').alertLine();
,仍然收到警报。但我想知道是否有指定的父的功能,例如对象,刺痛,数
function handler(selector) {
if (typeof(selector) == 'string'){
return String(selector);
}
if (typeof(selector) == 'number') {
return Number(selector);
}
if (typeof (selector) == 'object') {
return Object(selector);
}
}
handler.prototype.alertLine = function() {
alert(this);
}
handler('hello').alertLine();
我不介意Handler
为对象的方式或者不是唯一的问题,如果我传递值使用这种方法。
谢谢你提前。