A js type interview question, do not understand what to do? Ask for answers

Please write a js program that defines a list class List, that consists of two members: attribute length (representing the number of elements in the list) and method add (adding elements to the list), where the parameters of the constructor and add method are required to be dynamic.

Feb.26,2021


ES5

function List1(){            
            this.items = [];
            for(var i =0; i<arguments.length;iPP){
                this.items.push(arguments[i]);
            }
            this.length = arguments.length;
            this.add = function(){
                for(var i =0; i<arguments.length;iPP){
                    this.items.push(arguments[i]);
                }
                this.length = this.items.length;
            }
        }
Menu