javascript - Understanding Basic Prototyping & Updating Key/Value pairs -
first time poster, long time lurker.
i'm trying learn more advanced features of .js, , have 2 ojectives based on pasted code below:
- i add methods parent class in specific way (by invoking prototype).
- i intend update declared key/value pairs each time make associated method call. execmtaction seen in thesuper execute each function call, regardless. design.
here code:
function thesuper(){ this.options = {componenttype: "uitabbar", componentname: "visual browser", componentmethod: "select", componentvalue: null}; execmtaction(this.options.componenttype, this.options.componentname, this.options.componentmethod, this.options.componentvalue); }; thesuper.prototype.tapuitextview = function(val1, val2){ this.options = {componenttype: "uitextview", componentname: val1, componentmethod: "entertext", componentvalue: val2}; };
i execute (very simple):
thesuper.executemtaction(); thesuper.tapuitextview("a", "b");
unfortunately unable overwrite "this.options" in parent, , .tapuitextview method throws error saying cannot find executemtaction.
all want do, said, update parameters in parent, have executemtaction run each time make method call. that's it. thoughts? understand basic i'm coming long-time procedural career , .js seems have weird confluence of oo/procedural i'm having bit of difficulty with.
thanks input!
instead of doing this...
thesuper.prototype.tapuitextview = function(val1, val2){ this.options = {componenttype: "uitextview", componentname: val1, componentmethod: "entertext", componentvalue: val2}; };
you possibly update values of object instead of trying overwrite it...
this.options['componenttype'] = "uitextview"; this.options['componentname'] = val1; this.options['componentmethod'] = "entertext"; // etc...
i don't see you've defined 'executemtaction()'. think define 'executemtaction' in thesuper , execute methods w/ 'this'
function thesuper() { this.executemtaction = function(options) { // define... } } thesuper.prototype.amethodname = function(options) { this.execmtaction(options); }
you pass function parameter when making method call , use callback...
thesuper.prototype.amethodname = function(options, callback) { callback(options); } thesuper.amethodname(options, execmtaction);
sorry it's been long week me. may have missed asking for. hope helps some.
Comments
Post a Comment