In my object init, I am calling the methods with their names. But some time, those methods may not declared or I don't want to call them. in case of that chance, how to prevent my method from call?
here is my calling approach : this[collectionName]();
- here the name is parameter I receive. so the method is declared within object.
here is full code :
init: function( collectionName, size ){
if( (typeof this[collectionName] ) === undefined ) return; //but not works!!!
this.collectionName = collectionName;
this.size = size.toUpperCase() == "SMALL" ? 20 : size.toUpperCase() == "MEDIUM" ? 35 : lsize.toUpperCase() == "LARGE" ? 50 : "SMALL";
this[collectionName]();//some time method will not exist. how to check the existence and prevent it from call?
return this.generateRecords();
}
I am getting an error when the method is not their then :
New-DataModels.js?bust=1491457640410:69 Uncaught TypeError: this[collectionName] is not a function