【发布时间】:2019-07-01 15:44:21
【问题描述】:
我有这个示例函数,我想以这种格式调用它:
const myfunc = (string) => {
return string.length
}
console.log("check_length".myfunc())
我该怎么做? 提前感谢您的回答!
【问题讨论】:
-
所以你必须扩展字符串原型
标签: javascript
我有这个示例函数,我想以这种格式调用它:
const myfunc = (string) => {
return string.length
}
console.log("check_length".myfunc())
我该怎么做? 提前感谢您的回答!
【问题讨论】:
标签: javascript
唯一的办法是用访问this的经典函数改变String的原型。
String.prototype.myfunc = function () {
return this.length;
};
console.log("check_length".myfunc());
【讨论】: