小编use*_*120的帖子

Javascript:TypeError:...不是构造函数

我有一个TypeError问题:

function artist(name) {
    this.name = name;
    this.albums = new Array();

    this.addAlbum = function(albumName) {
        for (var i = 0; i < this.albums.length; i++) {
            if (this.albums[i].name == albumName) {
                return this.albums[i];
            }
        }

        var album = new album(albumName);
        this.albums.push(album);

        return album;
    }
}

function album(name) {
    this.name = name;
    this.songs = new Array();
    this.picture = null;

    this.addSong = function(songName, track) {
        var newSong = new songName(songName, track);
        this.songs.push(newSong);

        return newSong;
    }
}
Run Code Online (Sandbox Code Playgroud)

给出以下错误:

TypeError: album is not a constructor …

javascript constructor object typeerror

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

标签 统计

constructor ×1

javascript ×1

object ×1

typeerror ×1