Zillionnn 2016-03-26 09:02 采纳率: 28.6%
浏览 5119
已采纳

JS 中怎么把定义的对象的一个属性作为一个数组

function jsonObj(text, nodes){
            this.text =text;
            this.nodes =nodes;

        }

我想把nodes作为数组,这样可以插入多个对象,现在这样只能插一个对象

  • 写回答

2条回答 默认 最新

  • 斯洛文尼亚旅游 2016-03-26 11:35
    关注
     function jsonObj(text, nodes){
                this.text =text;
                this.nodes =[nodes];/////
    
            }
    jsonObj.prototype.add=function(node){
    this.nodes.push(node)
    }           
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?