gpt4 book ai didi

javascript - 在 JavaScript 中 init 期间调用函数的正确方法

转载 作者:行者123 更新时间:2023-12-03 09:29:16 25 4
gpt4 key购买 nike

我收到错误 method1 () 未定义。在 init 期间调用方法的正确方法是什么?

 gdmsDashboard.controller('DashboardController', '$scope') {

$scope.Msg = "";

(function init() {
$scope.method1 ();
method1 ();
this.method1 ();

})();

$scope.method1 = function () {
//
}
}

最佳答案

您需要了解variable hoisting概念

只是为了让你的代码工作,这样做

$scope.method1 = function () { 
//
}
(function init() {
$scope.method1();
})();

关于javascript - 在 JavaScript 中 init 期间调用函数的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31568060/

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