【发布时间】:2021-07-10 01:42:54
【问题描述】:
从将传递 jslint 的同一对象中的函数调用另一个函数的正确方法是什么?
任何信息将不胜感激!
用于说明目的的简单示例:
(function () {
"use strict";
var myObject = {
functionOne: function () {
console.log("functionOne called by functionTwo");
},
functionTwo: function () {
// jslint Error: 'myObject' is out of scope. (out_of_scope_a);
// What is the proper way to call another function inside the same Object that will pass jslint?
myObject.functionOne();
// jslint Error: Unexpected 'this'. (unexpected_a);
// What is the proper way to call another function inside the same Object that will pass jslint?
this.functionOne();
}
};
myObject.functionTwo();
}());
【问题讨论】:
-
我从您的代码中看到的唯一错误是
Unexpected 'this'.。myObject.functionOne();不会导致你描述的错误 -
this post 中的一些好建议。我会特别关注“告诉 JSLint 闭嘴……或者根本不要使用 JSLint”
-
是的,我强烈推荐使用更可配置、更少固执、更现代的东西,比如 ESLint。
-
感谢您的回复。 @CertainPerformance 你让我走上了正确的轨道。我有一个过时的 jslint 版本。最新版本不介意 myObject.functionOne();
标签: javascript scope jslint function-call object-literal