Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#199 closed defect (fixed)

Add a 'dojo.lang.bind' to deprecate prototype.js's bind.

Reported by: [email protected] Owned by: anonymous
Priority: high Milestone:
Component: General Version: 0.1
Keywords: bind scope Cc:
Blocked By: Blocking:



We're currently converting from prototype.js to dojo. During refactoring of our code we discovered a possible gap between prototype and dojo for binding functions to a scope. The current implementation of dojo.lang.hitch is:

dojo.lang.hitch = function(obj, meth){

return function(){ return obj[meth].apply(obj, arguments); }


This method is insufficent for binding functions declared as variables to a different scope because it requires that 'meth' be a property of 'obj'.

David Schontzler's idea was to add a method such as dojo.lang.bind that would bind a function to any scope. The logic might look something like:

dojo.lang.bind = function(obj, meth) {

return function() {return meth.apply(obj, arguments);};


We've already tested this code in our conversion and it seems to get the job done.

For your reference, the following is some code where dojo.lang.bind would be useful:

foo.prototype = {

bar: function() {

var url = '../api/foo_bar.php';

var callback = function(type, data, evt) {



url: url, load: dojo.lang.bind(this, callback), method: "get", mimetype: "application/xml"




Change History (2)

comment:1 Changed 17 years ago by david

Resolution: fixed
Status: newclosed

(In [2131]) fixes #199

comment:2 Changed 17 years ago by david

Keywords: bind scope added

[2134] is the "real" fix now (dojo.lang.hitch supports the bind call signature).

Note: See TracTickets for help on using tickets.