小编Aus*_*lia的帖子

未捕获的类型错误:追加不是函数

我想创建一个“人”数组并将它们记录到控制台。

这是我的代码:

$(document).ready(function () {
    function Person(firstName) {
        this.firstName = firstName;
        console.log('Person instantiated');
    }
    var people = new Array;
    people.append(new Person("Alice1"));
    people.append(new Person("Alice2"));
    people.append(new Person("Alice3"));
    people.append(new Person("Alice4"));

    for (var i = 0; i < people.length; i++) {
        console.log(people[i]);
    }
});
Run Code Online (Sandbox Code Playgroud)

但是,控制台会输出以下内容:

main.js:4 Person instantiated
jquery-3.1.1.min.js:2 jQuery.Deferred exception: people.append is not a function TypeError: people.append is not a function
    at HTMLDocument.<anonymous> (http://localhost:8383/p5/js/main.js:7:8)
    at j (http://localhost:8383/p5/js/jquery-3.1.1.min.js:2:29948)
    at k (http://localhost:8383/p5/js/jquery-3.1.1.min.js:2:30262) undefined
r.Deferred.exceptionHook @ jquery-3.1.1.min.js:2
k @ jquery-3.1.1.min.js:2
jquery-3.1.1.min.js:2 Uncaught TypeError: people.append is not …
Run Code Online (Sandbox Code Playgroud)

jquery

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

标签 统计

jquery ×1