ginebra2/chrome/js/Bind.js
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 
     1 
       
     2 // Bind a function’s scope at definition instead of execution.  Useful
       
     3 // for controlling the 'this' pointer in callbacks.
     2 Function.prototype.bind = function(obj) {
     4 Function.prototype.bind = function(obj) {
     3     var method = this,
     5     var method = this,
     4     temp = function() {
     6     temp = function() {
     5         return method.apply(obj, arguments);
     7         return method.apply(obj, arguments);
     6     };
     8     };
     7  
     9 
     8     return temp;
    10     return temp;
     9 } 
    11 }
    10 
    12 
    11 function createDelegate(object, method) {
    13 function createDelegate(object, method) {
    12     var shim = function()
    14     var shim = function()
    13         {
    15         {
    14             method.apply(object, arguments);
    16             method.apply(object, arguments);