我真的很困惑,我怎么能得到console.log不是第1091行的函数.如果我删除下面的闭包,第1091行不会抱怨这样的错误.Chrome版本43.0.2357.130(64位).

这是代码:
$scope.columnNameChanged = function (tableColumn) {
setDirtyColumn(tableColumn);
//propagate changes to the key fields
for (var i = 0; i < $scope.tableIndexes.length; ++i) {
for (var j = 0; j < $scope.tableIndexes[i].columnName.length; ++j) {
if ($scope.tableIndexes[i].columnName[j] === tableColumn.previousName) {
console.log('xxx', $scope.tableIndexes[i].columnName[j])
(function (i, j) {
$timeout(function () {
console.log($scope.tableIndexes[i].columnName[j])
$scope.tableIndexes[i].columnName[j] = tableColumn.name.toUpperCase();
console.log($scope.tableIndexes[i].columnName[j])
});
})(i, j);
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
Seb*_*mon 164
简单地;在console.log(... 后面加一个分号()).
该错误很容易重现,如下所示:
console.log()
(function(){})Run Code Online (Sandbox Code Playgroud)
它试图将function(){}参数传递给返回值,返回值console.log()本身不是函数,而是实际undefined(检查typeof console.log();).这是因为JavaScript将其解释为console.log()(function(){}).console.log但是是一个功能.
如果你没有console你看到的对象
ReferenceError:未定义控制台
如果你有console对象而不是log你看到的方法
TypeError:console.log不是函数
但是,你拥有的是什么
TypeError:console.log(...)不是函数
注意(...)函数名称后面.有了这些,它指的是函数的返回值.
;如果不存在分号,则所有这些代码段都会导致各种意外错误:
console.log() // As covered before
() // TypeError: console.log(...) is not a function
console.log() // Accessing property 0 of property 1 of the return value…
[1][0] // TypeError: console.log(...) is undefined
console.log() // Like undefined-3
-3 // NaN
Run Code Online (Sandbox Code Playgroud)
您(...)经常使用链式方法或链式属性访问器:
string.match(/someRegEx/)[0]
Run Code Online (Sandbox Code Playgroud)
如果没有发现,正则表达式,该方法将返回null和属性访问null将导致一个TypeError: string.match(...) is null -的返回值是null.在该情况下console.log(...)的返回值是undefined.
一个可能的原因可能是var console脚本中某处的声明。
用:
window.console.log(...);
Run Code Online (Sandbox Code Playgroud)
反而。为我工作。
我希望它有帮助
该错误意味着返回值的console.log()是不是一个函数。你缺少一个分号:
console.log('xxx', $scope.tableIndexes[i].columnName[j]);
// ^
Run Code Online (Sandbox Code Playgroud)
这使得(...)IIFE的以下内容被解释为函数调用。
比较错误信息
> var foo = {bar: undefined};
> foo.bar();
Uncaught TypeError: foo.bar is not a function
Run Code Online (Sandbox Code Playgroud)
和
> var foo = {bar: function(){}};
> foo.bar()();
Uncaught TypeError: foo.bar(...) is not a function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53490 次 |
| 最近记录: |