Is there a way to test circular reference in JavaScript?

前端 未结 5 516
暗喜
暗喜 2020-12-09 05:52

I\'m making a game, and I\'ve come across a problem... When I try to save, JSON fails and reports that circular reference is being made somewhere. I don\'t think it actually

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 06:27

    I was thinking about what you're trying to accomplish based off the initial code from your other question. Why not do something like this.

    Player = function()
    {
        this.UnitTypeXpower = 2
        this.UnitTypeYpower = 7
    
    }
    
    UnitTypeXAdd = function(owner)
    {
        owner.UnitTypeXpower++;   
    }
    

    That way you don't have to use a circular reference and it accomplishes the same thing.

提交回复
热议问题