Click here to Skip to main content
15,889,116 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Java Script Pin
manoj s sherje19-Dec-12 1:01
manoj s sherje19-Dec-12 1:01 
AnswerRe: Java Script Pin
ZurdoDev19-Dec-12 1:37
professionalZurdoDev19-Dec-12 1:37 
AnswerRe: Java Script Pin
vbmike19-Dec-12 4:28
vbmike19-Dec-12 4:28 
QuestionUsing datePicker to disable dates already selected Pin
xnaLearner11-Dec-12 3:39
xnaLearner11-Dec-12 3:39 
Questionjquery tabslideout plugin and wired behavior Pin
Tridip Bhattacharjee9-Dec-12 21:13
professionalTridip Bhattacharjee9-Dec-12 21:13 
AnswerRe: jquery tabslideout plugin and wired behavior Pin
Mayor Daily17-Dec-12 4:22
Mayor Daily17-Dec-12 4:22 
GeneralRe: jquery tabslideout plugin and wired behavior Pin
Tridip Bhattacharjee18-Dec-12 0:55
professionalTridip Bhattacharjee18-Dec-12 0:55 
QuestionNeed help understanding binding Pin
Steve Bondy7-Dec-12 14:00
Steve Bondy7-Dec-12 14:00 
Hi all,

I'm an old C++ programer who has dabbled in web coding and javascript over the years. Lately I've been trying to get a handle on the mooTools framework for javascript. I'm having a bit of trouble understanding how javascript handles binding, or it may be a mootools binding thing, I'm not sure. Any insight is appreciated.

The following code works:
C#
var myMenu = new Class({

    initialize: function(elements, options){
    <!-- <snip>  -->
    // Add mouseenter and mouseleave events to each of the menu elements
        this.elements.each(
        function(el,i){
                var obj = this;
                el.addEvent('mouseenter', function(evnt){
                   obj.menuOpen(i);
                });
                el.addEvent('mouseleave', function(evnt){
                   obj.menuOpen(null);
                });
            }.bind(this) // end of function(el,i)
    );  // end of this.elements.each

    }, // End of initialize function
  menuOpen(evnt, i) {
     .... do menu stuff ....
  }
  <!-- <snip>  -->
});


The anonymous function coded in-line with the call to addEvent works properly and my menu items open and close as expected. What I tried, because it looks better to my C++ trained eyes, and to see if I understood things correctly was this:

C#
var myMenu = new Class({

    initialize: function(elements, options){
    <!-- <snip>  -->

    mouseEnter: function(evnt, i){
                   this.menuOpen(evnt, i);
                },
    mouseLeave: function(evnt){
                   this.menuOpen(null);
                },

    // Add mouseenter and mouseleave events to each of the menu elements
    this.elements.each(
            function(evnt,i){
                var obj = this;
                el.addEvent('mouseenter', obj.mouseEnter(evnt, i));
                el.addEvent('mouseleave', obj.mouseLeave(evnt, i));
            }.bind(this) // end of function(el,i)
    );  // end of this.elements.each

  }, // End of initialize function

  menuOpen(evnt, i) {
     .... do menu stuff ....
  }
  <!-- <snip>  -->
});


This does not work (nothing happens), yet to me it looks like it should. I'm pretty sure it has to do with binding the functions to the proper object in the addEvent calls (or something) but none of the things I've tried have worked.

If you can give some clues to help me understand what's going wrong here I'd appreciate it.

Thanks,

Steve
QuestionText replace Pin
rakeshs3126-Dec-12 23:06
rakeshs3126-Dec-12 23:06 
AnswerRe: Text replace Pin
Richard MacCutchan7-Dec-12 0:43
mveRichard MacCutchan7-Dec-12 0:43 
GeneralRe: Text replace Pin
rakeshs3129-Dec-12 5:40
rakeshs3129-Dec-12 5:40 
QuestionJQuery datePicker SelectMultiple format dd/mm/yy Pin
xnaLearner6-Dec-12 0:37
xnaLearner6-Dec-12 0:37 
AnswerRe: JQuery datePicker SelectMultiple format dd/mm/yy Pin
srinivas nv6-Dec-12 21:50
srinivas nv6-Dec-12 21:50 
GeneralRe: JQuery datePicker SelectMultiple format dd/mm/yy Pin
xnaLearner10-Dec-12 0:04
xnaLearner10-Dec-12 0:04 
QuestionDelete selected rows by table id using javascript Pin
Member 88023075-Dec-12 8:05
Member 88023075-Dec-12 8:05 
AnswerRe: Delete selected rows by table id using javascript Pin
Deepak Kr15-Dec-12 18:45
Deepak Kr15-Dec-12 18:45 
GeneralRe: Delete selected rows by table id using javascript Pin
Member 88023076-Dec-12 6:20
Member 88023076-Dec-12 6:20 
AnswerRe: Delete selected rows by table id using javascript Pin
Graham Breach6-Dec-12 21:41
Graham Breach6-Dec-12 21:41 
QuestionHTML5 Javascript Issue Pin
#realJSOP3-Dec-12 1:09
mve#realJSOP3-Dec-12 1:09 
AnswerRe: HTML5 Javascript Issue Pin
Graham Breach3-Dec-12 5:00
Graham Breach3-Dec-12 5:00 
GeneralRe: HTML5 Javascript Issue Pin
#realJSOP3-Dec-12 5:22
mve#realJSOP3-Dec-12 5:22 
GeneralRe: HTML5 Javascript Issue Pin
Graham Breach3-Dec-12 6:29
Graham Breach3-Dec-12 6:29 
GeneralRe: HTML5 Javascript Issue Pin
#realJSOP3-Dec-12 6:40
mve#realJSOP3-Dec-12 6:40 
GeneralRe: HTML5 Javascript Issue Pin
Graham Breach3-Dec-12 6:48
Graham Breach3-Dec-12 6:48 
GeneralRe: HTML5 Javascript Issue Pin
#realJSOP3-Dec-12 9:09
mve#realJSOP3-Dec-12 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.