我有这个示例函数,我想以这种格式调用它:
const myfunc = (string) => {
return string.length
}
console.log("check_length".myfunc())
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?预先感谢您的答复!
唯一的方法是String使用经典的访问功能来变异的原型this。
String.prototype.myfunc = function () {
return this.length;
};
console.log("check_length".myfunc());Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48 次 |
| 最近记录: |