This vs Class name in Javascript

I’m using a code snippet from someone else and I can’t seem to understand when he’s using this and when he’s using the name of the class

On line 3 he uses this.pusher, while in the $.each function he’s using chat.pusher ( the name of the current object )

connect : function ( )
{
    if ( typeof Pusher !== 'undefined' )
    {

        this.pusher = new Pusher( config.pusher_app_key , { encrypted : true, authEndpoint : '/chat.php' , auth : { params : { hash : app.session.get(), mobile : app.mobile } } } );

        $.each( chat.channels , function ( channel_type , channel_name ) {

            chat.pusher.subscribe( channel_name );

            if ( chat.events[ channel_type ] )
                $.each( chat.events[ channel_type ] , function ( event_name , callback ) {
                    chat.pusher.channels.channels[ channel_name ].bind( event_name , chat.events[ channel_type ][ event_name ] );
                });

        });
},

I also added a screenshot which shows a clear overview of the situation.

enter image description here


Source: oop

Leave a Reply