gpt4 book ai didi

javascript - 如何将文件的内容添加到javascript函数

转载 作者:行者123 更新时间:2023-11-28 08:12:58 24 4
gpt4 key购买 nike

我想用另一个文件的内容填充 anglarjs 函数的内容。可能是js文件,json,txt,我不介意。

test.js

$scope.startTest = function () {
/**
* insert content of details-1.js
*/
}

detials-1.js

var fac = 3;
return fac;

最终的函数看起来像这样

$scope.stratTest = function() {
var fac = 3;
return fac;
}

我的目标是根据您选择的测试拥有不同的测试过程,并从 startTest 函数启动特定的测试过程。

最佳答案

你可能应该做这样的事情。

details-1.js

$scope.tests.myTest = function() {
// Insert test here
}

test.js

$scope.startTest = function() {
// Loop through all tests
for (var key in $scope.tests) {
if ($scope.tests.hasOwnProperty(key)) {
// Execute test
$scope.tests[key]( /* args here */ );
}
}

// Or you could just execute a specific test
$scope.tests.myTest( /* args here */ )
}

注意: $scope.tests 应该在某处初始化。

关于javascript - 如何将文件的内容添加到javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23957276/

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