这是一个javascript函数:
String.prototype.digit = function() {
console.log(this); // 'this' contain the object
return false;
};
如何在调用函数时访问函数中的参数'14'
,如下所示:
'14'.digit();
答案 0 :(得分:5)
您可以使用Object#valueOf
方法
valueOf()
方法返回指定对象的原始值。
String.prototype.digit = function() {
console.log(this.valueOf());
return false;
};
'14'.digit();
或Object#toString
方法。
toString()
方法返回表示对象的字符串。
String.prototype.digit = function() {
console.log(this.toString());
return false;
};
'14'.digit();