gpt4 book ai didi

javascript - 如何访问javascript函数中的参数

转载 作者:行者123 更新时间:2023-11-30 08:27:54 25 4
gpt4 key购买 nike

这是一个 javascript 函数:

String.prototype.digit = function() {
console.log(this); // 'this' contain the object
return false;
};

如何在调用函数时访问函数中的参数 '14':

'14'.digit();

最佳答案

你可以使用 Object#valueOf方法

The valueOf() method returns the primitive value of the specified object.

String.prototype.digit = function() {
console.log(this.valueOf());
return false;
};

'14'.digit();

Object#toString方法。

The toString() method returns a string representing the object.

String.prototype.digit = function() {
console.log(this.toString());
return false;
};

'14'.digit();

关于javascript - 如何访问javascript函数中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42344868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com