Created
December 20, 2012 14:31
-
-
Save lgedeon/4345601 to your computer and use it in GitHub Desktop.
My first JS Hooks idea. Things got complex shortly after this :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* bind to variable */ | |
jQuery(document).ready(function() { | |
// register a filter and override the functions | |
jQuery('body').bind('myTrig', function(event, obj) { | |
obj.valueOf=obj.toSource=obj.toString=function(){return "blue"}; | |
}); | |
// create a variable as an object and pass it to any filters that have been registered | |
var o = Object('green'); | |
jQuery('body').trigger('myTrig', o); | |
alert(o); // should return blue | |
}); | |
/* bind to object */ | |
jQuery(document).ready(function() { | |
// register a filter | |
jQuery('body').bind('myTrig', function(event, obj) { | |
obj.value = "blue"; // set the value of the object instead of returning a value | |
}); | |
// create an object and pass it to any filters that have been registered | |
var o = {value: 'green'}; | |
jQuery('body').trigger('myTrig', o); | |
alert(o); // should return blue | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment