Skip to content

Commit

Permalink
Working bind all.. still a little hackky tho..
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Jun 3, 2014
1 parent fb5424f commit ee0bce9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 4 additions & 7 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@
if (_.isFunction(_function) ){
var oldFunction = _function;

protoProps[functionName] = function(){
console.log('this', this);
if (this === undefined || this === null) {
self[functionName] = function(){
if (this === root || this === self || this === undefined || this === null) {
// Undefined so need to bind this:
console.log('bound to self!!!');
oldFunction.apply(self, arguments);
} else {
console.log("bound to old this... must be on new Obj")
console.log(arguments);
oldFunction.apply(this, arguments);
}

Expand Down Expand Up @@ -1081,6 +1077,7 @@

// Should ovewrite this if you want to bindAll explicitly.
preInit: function(protoProps){
preInitialize(this, protoProps);
},

// Initialize is an empty function by default. Override it with your own
Expand Down Expand Up @@ -1692,7 +1689,7 @@
// Add prototype properties (instance properties) to the subclass,
// if supplied.
// preInitialize
preInitialize( child, protoProps);
// preInitialize( child, protoProps);
if (protoProps) _.extend(child.prototype, protoProps);

// Set a convenience property in case the parent's prototype is needed
Expand Down
8 changes: 5 additions & 3 deletions test/testBindAll.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
//
new (Backbone.View.extend({
var vv = new (Backbone.View.extend({
a: 5,

initialize: function(){
console.log("!");
var mmmmm = new this.blah();
setTimeout(this.blah, 100);
$(document).on('click', this.click);

},

blah: function() {
console.log(this.a);
console.log("should be..... a number:", this.a);
},

click: function() {
console.log(this.a);
//console.log(this.a);
}
}))();

Expand Down

0 comments on commit ee0bce9

Please sign in to comment.