Skip to content

Instantly share code, notes, and snippets.

@jessebeach
Created June 7, 2011 03:56
Show Gist options
  • Save jessebeach/1011660 to your computer and use it in GitHub Desktop.
Save jessebeach/1011660 to your computer and use it in GitHub Desktop.
jQuery proxy with arguments
<!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