javascript - Self-executing function in object initialiser can't see object's properties -
i know function scope, self-executing functions, hoisting , other cool words, totally of-base following.
var o = { : 1, f : (function(){ console.log(this.a); })() }; why gives me undefined? function self-executed right when object initialized, therefore expect assign 1. not doing this.
because you're not calling via o, this not o.
additionally never assing function either - f set return value (undefined).
Comments
Post a Comment