Dynamically Auto-Linking instance variables to object functions in javascript / jquery? -


I'm trying to create a strong audio player in JavaScript (& amp; jQuery). I know that there are other players, but I want to try to make my own (so please do not see me on jquery plugins). Essentially what I would like to do:

Main.js:

  var player = new player (audio observer); // audio audio link for audio class (not shown) player. Buttons.play = $ ('play'); Player.buttons.pause = $ ('Pause'); // Play the link of the ID for the HTML document element and stop  

Player.js:

  Player = function ( Audio) {This.Audio = Audio; This.buttons = {}; (Var buttons in this.buttons) {button.live ('click', this.button); // This is the line that I do not know about.}} Player.prototype = {play: function () {// Do Something}, stop: function () {// something}}  

Therefore, I would like to pre-link properties to object functions when you initialize the player, and when I link it to an HTML element, then do this work is.

Thank you! Matt Mueller

I think it would be more oo way to go. Set two more functions inside the player A function registers a UI element in a player action and to cancel the second action. Instead of keeping a clear button archive you can just lean over jQuery.live and jQuery.die. For example:

  Function Register Action (selector, verb) {// You can have some arguments to map / action the action passed to the actual action name $ (selector). ', Action / function_name); } Function unRegisterAction (selector, [action]) {// You may have some argument to pass the actual action name $ (selector) into action .die ('click', [action / functionName]); }  

After that, your main.js example will be created from the top:

  var player = new player (audio observer); // audio object link for audio class (not shown) player. Registrar Action ('# Play', Play); Player.registerAction ('#Pause', Pause);  
  Player = function (audio) {this.Audio ============================== ===================== AUDIO; }  

Or something like that.


Comments

Popular posts from this blog

MVP, design question -

excel - Populate list via a bi-Condition -

iphone - How do I make a UIPickerView in a UIActionSheet -