Javascript replace a function with a new one containing dynamic contents -
my javascript knowledge less experienced, might use wrong descriptions in following.
i have object in static .js file:
var info = { methoda: function() { // call methodb. this.methodb('test'); }, methodb: function(value) { // stuff } }
now, in .aspx file, create function methodc(value) varying contents (depending on data), want insert instead of above definition of methodb(value):
... var methodc = function(value) { // different stuff } ...
my idea has far been replace methodb methodc in following fashion:
... info.methodb = methodc; ...
using ie's buildin developer tool, following error when calling this.methodb('test'); info.methoda():
object doesn’t support property or method
removing 'this' this.methodb('test') results in error:
object expected
i don't errors using firebug - because use various frameworks, might catch error.
how should or should use different approach?
regards, casper
it should work, doing right way. problem lays elsewhere.
update: should still work long call methoda on object, eg info.methoda().
maybe not understanding error messages ?
"object doesn’t support property or method" means in expression "this.methodb()", this doesn't have property named "methodb". means this not info when code of methoda executed.
"object expected" means variable methodb unknown in current execution context. of course is, since methodb never variable, property of info.
to debug problem, need know this when code executed, , why it's not think should be. when call info.methoda(), this set info when methoda begins execution.
Comments
Post a Comment