Old school functions calling each other

65 views
Skip to first unread message

Sarah King

unread,
Oct 4, 2014, 12:44:37 AM10/4/14
to threed...@googlegroups.com
I'm a bit old school so I avoid anonymous functions if possible - I find the code more readable and easier to maintain a year from now when I have to tweak something.

I want to incorporate the Click function into the Start function and rather than repeat the code I thought I'd just call the function. However when called that way the function has no concept of $(this)

How do I call the click function and still have it work?


                function btchDragStart(ev, dd) {
                    console.log('btchDragStart');
                    btchBoxClick();
                }
                
                function btchBoxClick(){
                    console.log('btchBoxClick');
                    $('.btchPanel').hide(); 
                    var panelName = $(this).attr('id').substr(0,boxId.length-3); 
                    $('#'+panelName).show(); 
                    $(this).css('zIndex', z++); 
}

                function btchDragged(ev, dd) {
                    console.log('btchDragged');
                }

                function btchDragEnd(ev) {
                    console.log('btchDragEnd');
                }
                //----------------------------------------------------------
                //dragging and resizing
                //----------------------------------------------------------        
                $('.drag')
                        .drag("start", btchDragStart)
                        .click(btchBoxClick)
                        .drag(btchDragged)
                        .drag('dragend', btchDragEnd);
                
                

Marty Nelson

unread,
Oct 8, 2014, 12:57:25 PM10/8/14
to threed...@googlegroups.com
var drag = $('.drag')
drag
    .drag("start", btchDragStart.bind(drag))
    .click(btchBoxClick.bind(drag))
    .drag(btchDragged.bind(drag))
    .drag('dragend', btchDragEnd.bind(drag));

Reply all
Reply to author
Forward
0 new messages