Question

Is there a way to use options in jqueryUI widgets without having to type this.options.optionName every time? Sometimes I will create a variable in a private function that is shorter and make it equal the option, but this decreases the scope of that shorthand var. Other times I create a var outside the widget to increase the scope, but this is messy.

options: {
name: 'Video',
v: null
},

...

this.options.v = document.getElementById(id);
this.options.v.play();

ex: is there a way to by default just use v.play() without setting this.options.v = v = document.getElementById(id) inside a private function? Even something like this.o.v would be helpful, although doesn't solve some problems where jQuery can get tripped up with the dot notation.

Was it helpful?

Solution

One way I started implementing: In the create and init function, I just pass all my options vars into public and private functions where i can then access objects with shorthand vars.

For instance,

_initVideo: function() {
    var that = this;
    this.options.v.addEventListener('progress', function() {
    that.updateProgress(that.options.v,that.options.c,that.options.p);
    });
},
updateProgress: function(v,c,p) {

    var max = v.duration;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top