im currently building an MVC Framework in NodeJS but iv’e come across a little issue, when im checking to see if a method exists in a controller im doing the following:
var controller = new (this.appManager.getControllerObj(this.route.controller))();
var method = this.route.method;
if(method in controller)
{
/*
* Method exists within controller
* */
}
But obviously the object type has native prototypes, so if I access my site with the following: https://localhost/index/__proto__ it obviously tries to route that method.
Now I know that I can simply black list specific methods but is there a better approach to accomplish this
Update:
This seem’s to work fine:
if((method in controller) && !controller.hasOwnProperty(method))
{
/*
* Method exists within controller
* */
}
Thanks
You can use:
Google for hasOwnProperty to learn more about it