Last Updated: February 25, 2016
·
806
· ydeshayes

Javascript undefined properties problems

If you want to create child object in an indefined javascript object, you can use the $parse function of angularJS.

For example:

Let's say I have one object car:

var car={};

Now I want to give this to my object directly: car.engine.piston

Javascript will tell me that I can't read piston of an undefined object because engine is not defined at this point but if I use the $parse function I can do this:

var getter = $parse('car.engine.piston');
var setter = getter.assign;

setter(this, 'value');

And my car.engine.piston will now exist !

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside