js对象中调用属性中的方法错误
在js代码中遇到以下错误:
typeerror: this.fn1 is not a function
原因是以下代码段:
test.exec = function() { return fn.fn1(); }
其中,fn对象尚未解析完毕,因此无法在对象内部引用其成员fn1。
要解决此问题,可以将代码重写为:
test.fn = { fn1: test.a }; test.exec = function() { return test.fn.fn1(); }
这种方式先将外部函数test.a复制到嵌套对象test.fn中,然后再引用test.fn。
以上就是JS对象中调用属性方法出错:如何解决 “TypeError: this.fn1 is not a function”?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号