JavaScript property inheritance

后端 未结 2 1196
醉话见心
醉话见心 2020-12-28 20:26

I\'m trying to have a generic \'List\' class, which will have:

  • Property: Items - which would be an array of \'what-ever\'
  • Method: Add() - which would
2条回答
  •  醉梦人生
    2020-12-28 20:32

    Try this:

    function CDList(){
        List.call( this )
        this.Add = function(Artist){
            this.Items.push(Artist)
        }
    }
    

    You need to call the superconstructor...

    I like this article of the MDN network about JavaScript inheritance. I tried this method/technique and it works very fine in all browsers I tested (Chrome, Safari, Internet Explorer 8+, and Firefox)..

提交回复
热议问题