javascript - How to assign a class method to a default property (i.e. reference non-static methods from a static scope) -


i have plugin has extendable transitions (used when new panels of data shown). comes default transition methods of:

  • "none" - replace data
  • "slide" - slide out existing panel , slide in new one
  • "fade" - fade out existing panel fade in new one

the various transition methods exist properties of transitions property on default options object:

e.g.

module myplugins {     export class myplugin     {         static defaultoptions =         {             // transition methods - can extended add new transitions             transitions:             {                 none: function (transition): jquerypromise<any>                 {                     return transition.$panel.toggle(transition.inward).promise();                 },                 slide: function (transition: transitioneventparams): jquerypromise<any>                 {                     return this._slide(transition);                 },                 fade: function (transition: transitioneventparams): jquerypromise<any>                 {                     return this._fade(transition);                 }             }         }          // simplified example class method         private _fade(transition: transitioneventparams): jquerypromise<any>         {             var $panel = transition.$panel;             if (transition.inward)             {                 return $panel.fadein(transition.duration).promise();             }             else             {                 return $panel.fadeout(transition.duration).promise();             }         }     } } 

at runtime transition methods called name, using plugin current this:

 promise = this.o.transitions[transition].call(this, transitionparams); 

now question is: possible reference class methods, static defaults, anonymous function wrappers not needed

e.g. want able have like:

static defaultoptions = {     // transition methods - can extended add new transitions     transitions:     {         ...         slide: myplugin._slide,         fade: myplugin._fade     } 

but can't figure out how reference non-static class methods, except name (e.g. object["methodname"].call(this, params)), static object.

any ideas on how simplify default options? should make helper methods static too, given plugin value of this?

you should able access "instance" methods statically on prototype, like

transitions: {     …     slide: myplugin.prototype._slide,     fade: myplugin.prototype._fade } 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -