Check method exist within class
by Joe Saad
HTML
<div id="main"></div>
CSS
#main {
border: 1px solid red;
background: blue;
height: 100px;
}
JavaScript
var Panel = function(obj) {
this.maxWidth = function(max_width) {
document.getElementById(obj.id).style.maxWidth = max_width;
};
for (var prop in obj) {
if (typeof this[prop] == 'function') { // ?? please help with this check
console.log('calling this.maxWidth now');
this[prop](obj[prop]); // call this method with right argument in this case will be this.maxWidth("200px")
}
}
};
var myObj = {
"id": "main",
"maxWidth": "200px"
};
var p = new Panel(myObj);