Skip to content

Instantly share code, notes, and snippets.

@presci
Created December 31, 2013 22:44
Show Gist options
  • Save presci/8202994 to your computer and use it in GitHub Desktop.
Save presci/8202994 to your computer and use it in GitHub Desktop.
bind.args
<html>
<head></head>
<body>
<div id="leaf"></div>
<div id="low"></div>
<input type="button" id="query" value="query"></button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var discovery=function(){
};
discovery.prototype.init=function(){
$('#leaf').html('hello world');
$('#query').click(this.cb('helloworld'));
};
discovery.prototype.helloworld=function(){
$('#low').html('ellho world');
};
discovery.prototype.cb = function(eventName, otherArgs) {
var bindArgs = [this];
if (Object.prototype.toString.call(otherArgs) !== '[object Array]') {
otherArgs = [];
}
var bind = Function.prototype.bind;
return bind.apply(this[eventName], bindArgs.concat(otherArgs));
};
var _=new discovery();
_.init();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment