Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I define the following json:
C#
var testobj = {
    firstfunc: function(){
        return setInterval(this.testfunc, 1000);
    },
    testfunc: function(){
        console.log('test');
        this.otherfunc();
    },
    otherfunc: function(){
        console.log('otherfunc');
    }
}


if I call testobj.testfunc(), the console prints "test" and "otherfunc". Fine so far.

if I call firstfunc with a intervall, that calls "otherfunc" inside, the console prints: this.otherfunc is not a function.
But this.otherfunc is a function and works if I call it inside testfunc.
Posted
Updated 29-May-14 0:39am
v2

As soon as you want to include function member, this is not JSON: http://en.wikipedia.org/wiki/JSON[^].

JSON is nothing but a subset of Javascript codes. The problem is unclear at all. How is that related to JSON at all? Please read the article above.

—SA
 
Share this answer
 
I think the problem is with the a scope of the function
Your setInterval function does not have the scope of your otherfunc as you are using it inside your json.

you should use object to call the function, that too after creating the object otherwise it would give error again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900