Last Updated: February 25, 2016
·
544
· 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 !