Created
June 7, 2011 03:56
-
-
Save jessebeach/1011660 to your computer and use it in GitHub Desktop.
jQuery proxy with arguments
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Untitled</title> | |
<meta name="viewport" content="width=device-width" /> | |
<!--[if lt IE 9]> | |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<style type="text/css"> | |
</style> | |
<script src="jquery/jquery.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
var a = { | |
f: function (b) { | |
console.log("This is the argument: "+ b); | |
} | |
}; | |
var d = "win"; | |
var c = $.proxy(a.f, a, d); | |
d = "fail"; | |
c(); /* output: This is the argument: win */ | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment