www.webdeveloper.com
Results 1 to 5 of 5

Thread: $(this) != this

  1. #1
    Join Date
    Jan 2008
    Posts
    273

    $(this) != this

    Hi All

    I need to monitor an object (instance variable) for events. So I thought I do:

    Code:
    function Xyz() {
        this.test = function(){
          console.log('this is test');
          $(this).trigger('abc') ;
        }
    }
    
    var x = new Xyz() ;
    x.test() ; 
    $(x).bind('abc', function(e){
        alert("ABC");
    }) ;
    The code does work, but doesn't show the alert. Any ideas how to fix this

    ps see the code working here

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    You're triggering the event before you bind it. Move x.test() below your bind statement, and everything should be fine.

    Another concern is that, according to the jQuery docs, the jQuery function is meant to take a DOM element, not a generic object. And though it seems to work for now, it might break in a later version of jQuery since it isn't a documented behavior.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Jan 2008
    Posts
    273
    check, stupid mistake!

    What would be the alternative for trigger/bind for Objects ?

  4. #4
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    What would be the alternative for trigger/bind for Objects ?
    In jQuery, there doesn't seem to be any, at least none that are officially supported. You'll have to look to other libraries for documented and supported custom events.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  5. #5
    Join Date
    Jan 2008
    Posts
    273
    ok, thanks a lot!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles