1
这是一个JavaScript函数:如何访问参数中的JavaScript功能
String.prototype.digit = function() {
console.log(this); // 'this' contain the object
return false;
};
如何访问参数'14'
的功能,而调用函数是这样的:
'14'.digit();
这是一个JavaScript函数:如何访问参数中的JavaScript功能
String.prototype.digit = function() {
console.log(this); // 'this' contain the object
return false;
};
如何访问参数'14'
的功能,而调用函数是这样的:
'14'.digit();
你可以使用Object#valueOf
方法
The
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();
谢谢...... !!!工作:) –
供参考:一个适当的函数调用会像'函数(ARG){的console.log(ARG); }' 关键字'this'不是参数,而是您从中调用函数的对象。 – getjackx