[removed] TypeError: … is not a constructor

前端 未结 1 2040
粉色の甜心
粉色の甜心 2020-12-06 01:06

I have a TypeError problem:

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

    this.addAlbum = function(albumName) {
        f         


        
相关标签:
1条回答
  • 2020-12-06 01:42

    This line

    var album = new album(albumName);
    

    shadows the external album function. So yes, album isn't a constructor inside the function. To be more precise it's undefined at this point.

    To avoid this kind of problem, I'd suggest naming your "classes" starting with an uppercase :

    function Album(name) {
    

    More generally I'd suggest to follow the Google style guide when in doubt.

    0 讨论(0)
提交回复
热议问题