oop - Function for all prototypes - Javascript -


i'm working on video player video.js. on side i've got elements (volume, fullscreen, play, pause...) prototypes. on other side i've got functions parse() going use of canvas prototypes (they come different elements).

parse function :

vjs.parsehex = function(c) {     if(c.charat(0) == "#") {         return c.substring(1,7);     } else if(c.substr(0,2) == "0x") {         return c.substring(2,8);     } else {         return c;     } },  vjs.parsered = function(c) {     return parseint((this.parsehex(c)).substring(0,2),16); },  vjs.parsegreen = function(c) {     return parseint((this.parsehex(c)).substring(2,4),16); },  vjs.parseblue = function(c) {     return parseint((this.parsehex(c)).substring(4,6),16); } 

an exemple of canvas prototype :

js.volumebar.prototype.drawsound = function(){   .   .   . } 

i want parse functions accessible of different prototypes. possible ? if yes, how can that?

thank helping me, léa.

it seems vjs sort of util namespace contains few functions should used in different places. long public can used anywhere:

vjs = {}; vjs.parsehex = function(c) { /*...*/ } vjs.parsered = function(c) { /*...*/ }   js.volumebar.prototype.drawsound = function(){   vjs.parsered(stuff); } 

keep in mind if pass vjs.parsered callback, called different object this expect. rewrite either

  • replace this vjs:

    vjs.parsered = function(c) { return parseint((vjs.parsehex(c)).substring(0,2),16); }

  • bind functions when pass them parameters:

    doasync(vjs.parsered.bind(vjs));

  • or bind them when define them:

    vjs.parsered = function(c) { /*...*/ }.bind(vjs);


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -