var people = { name: ["abc", "Jack", "Pepter", "Jim"], function() { return function () { var i = Math.floor ((Math.random () * 4)); return { this. name[i] }; };}; var myName = people.getname (); alert ("name is" +myname (). N);
In fact, the above code is printed nams is Undefiend, because the returned function inside this is not people inside the This,
1 typescript can be modified with lambads expression
is to use the lambads expression to resolve the this issue is not found.
2 If you use JS can be modified like the following
var people = { name: ["abc", "Jack", "Pepter", "Jim"], function() { var This . Name; return function () { var i = Math.floor ((Math.random () * 4)); return { n:name2[i] } ;};}; var myName = people.getname (); alert ("name is" +myname (). N);
Typescript Lambads resolved the This keyword cannot find a property