What is the context of an anonymous function?
问题 I have code like this: function demo() { this.val=5; function() { this.val=7; }(); } Now when I give execute this code in the firefox or chrome console it gives a syntax error. I don't understand why this is an error because I have read that javascript functions are objects so when I call the anonymous function, inside it this points to function demo and should change the val to 7 , so if I do var x=new demo(); x.val; //should give 7 but when I do this function demo() { this.val=5; var f