0
我从下面的代码中获得期望的输出。这些是打印数据JavaScript函数不能从另一个函数调用
(function(){
var getData=function()
{
console.log("getdata");
},
setData=function()
{
getData();
console.log("setData");
};
setData();
})();
但是当我尝试这样的事情在另一个page.I没有得到期望的输出两个JavaScript函数表达式。
这是我的代码。
var employeesList = {
getemployees: function() {
var data= getData("Employees/GetEmployees");
},
init: function() {
this.getemployees();
}
}.init();
var getData = function (url) {
var error = false;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function (data) {
return data;
},
error: function() {
return error = true;
}
});
};
我得到了这样的错误。 getData不是函数 请大家帮忙。
移动'变种的getData =函数(URL){''以上变种employeesList = {' –
确保功能在[范围]中所定义或可访问的(https://scotch.io/tutorials/understanding-范围式的JavaScript)。 – Ninjaneer
或者声明它像'function functionName(){}'而不是使用变量。这样它才能在声明之前可用。 – Hissvard