Dave's Brain

Browse - Programming Tips - JavaScript: How can I pass along "this" ?

Date: 2017jan8
Language: javaScript
Keywords: apply, call, bind

Q.  JavaScript: How can I pass along "this" ?

A.  Invoke the function with call() or apply().

For example:
$(this).click(function(event) { onClickThing.call(this, dlg, event); } // ^^^^ );
function onClickThing(dlg, event) { var thing = $(this).attr('thing'); }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.