相关疑难解决方法(0)

TypeError:console.log(...)不是函数

我真的很困惑,我怎么能得到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)

javascript

80
推荐指数
3
解决办法
5万
查看次数

什么是中间值?

今天我完全碰到了这个问题:Uncaught TypeError :(中间值)(...)不是函数

所以是的,在适当的位置放置分号后,它不再抛出该错误.但是,我从来不知道javascript中有这样的概念(intermediate value).

显然,您可以使用以下代码生成该错误的类似变体:

[myFunc] = function(someVar){
	
	console.log(someVar);
	return 7;
}();

//error thrown: (intermediate value) is not a function or its return value is not iterable
Run Code Online (Sandbox Code Playgroud)

如果你命名这个函数,它不再是intermediate:

function hi(){return undefined}

[a] = hi(); 

// error thrown: hi is not a function or its return value is not iterable
Run Code Online (Sandbox Code Playgroud)

我理解它指的是中间的东西,但在这种情况下我们有一个匿名函数,并且有方法来确定函数是否是匿名的,因此错误消息可能更明确一些.

搜索js mozilla mdn我找到了这个页面,Array.from可以找到"中间数组"的概念:

更清楚的Array.from(obj, mapFn, thisArg)Array.from(obj).map(mapFn, thisArg),除了不创建中间数组之外,具有相同的结果.

但除了这里和那里的信息之外,还不清楚中间值是什么. …

javascript

11
推荐指数
2
解决办法
8248
查看次数

在字符串上找不到 .substring 函数

在这个片段中,我试图从链接的 href 中提取一个子字符串。

let current_link = $(data, ownerDocument).find('#footbar>span>a[href^="/shortlinks"]').attr('href');
let current_number = current_link.substr(current_link.indexOf('/dex/')+5);
Run Code Online (Sandbox Code Playgroud)

出于某种原因,当我在第二个中断点并在控制台中评估该行时,我得到了我期望的子字符串,但是当我让脚本在没有断点的情况下运行时,我收到以下错误:

jQuery.Deferred exception: current_link.substr(...) is not a function
TypeError: current_link.substr(...) is not a function
Run Code Online (Sandbox Code Playgroud)

我添加了一些调试来向自己证明这current_link实际上是一个字符串:

let current_link = $(data, ownerDocument).find('#footbar>span>a[href^="/shortlinks"]').attr('href');
console.log(typeof(current_link)) // debugging
console.log(Object.getPrototypeOf(current_link)); // debugging
let current_number = current_link.substr(current_link.indexOf('/dex/')+5);
Run Code Online (Sandbox Code Playgroud)

打印出的两个 console.log 行:

> string
> String {"", constructor: ƒ, anchor: ƒ, big: ƒ, blink: ƒ, …}
>     anchor: ƒ anchor()
      ...
>     substr: ƒ substr()
      ....
>     __proto__: Object
>     [[PrimitiveValue]]: ""
Run Code Online (Sandbox Code Playgroud)

我已经回顾了三个相似但我认为不适用的问题,因为通过原型我知道这current_link是一个字符串: …

javascript

6
推荐指数
0
解决办法
97
查看次数

标签 统计

javascript ×3