Adi*_*hra 1 javascript function
这是一个javascript函数:
String.prototype.digit = function() {
console.log(this); // 'this' contain the object
return false;
};
Run Code Online (Sandbox Code Playgroud)
如何'14'在调用函数时访问函数中的参数,如下所示:
'14'.digit();
Run Code Online (Sandbox Code Playgroud)
你可以使用Object#valueOf方法
该
valueOf()方法返回指定对象的原始值.
String.prototype.digit = function() {
console.log(this.valueOf());
return false;
};
'14'.digit();Run Code Online (Sandbox Code Playgroud)
或Object#toString方法.
该
toString()方法返回表示对象的字符串.
String.prototype.digit = function() {
console.log(this.toString());
return false;
};
'14'.digit();Run Code Online (Sandbox Code Playgroud)