Skip to content

Commit

Permalink
Bug with .. nested inits.. kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Jun 3, 2014
1 parent fdb3dbc commit b8a97ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
17 changes: 4 additions & 13 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@
// form param named `model`.
Backbone.emulateJSON = false;

var propagateProps = function(self, protoProps){
var propagateProps = function(realSelf, self, protoProps){

_.each(protoProps, function(_function, functionName){
// We are checking we are not a Model, View, or Collection, and only
// a regular function.


var that = this;
var initializer = function(){

Expand All @@ -78,9 +77,10 @@
var oldFunction = _function;

self[functionName] = function(){

if (this === that || this === undefined || this === null) {
// Undefined so need to bind this:
return oldFunction.apply(self, arguments);
return oldFunction.apply(realSelf, arguments);
} else {
return oldFunction.apply(this, arguments);
}
Expand All @@ -97,17 +97,8 @@
};
// preInitialize function for Models, Views, and collections to avoid bindAll
var preInitialize = function(self, protoProps){
// Better way to compare this as opposed to root
/*
if (self.constructor.__parent__ && self.constructor.__parent__.__protoProps__){
debugger;
propagateProps(self.constructor.prototype, self.constructor.__parent__.__protoProps__);
} */


// TODO: recursive
new propagateProps(self.constructor.prototype, protoProps);
new propagateProps(self, self.constructor.prototype, protoProps);

};

Expand Down
47 changes: 47 additions & 0 deletions test/testBindAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,50 @@ var vv = new (Backbone.View.extend({
}))();





//////

//
var p = Backbone.View.extend({
a: 5,

initialize: function(){
var self = this;
console.log("!");
this.blah.apply({ a: 6}, []);
var mmmmm = new this.blah();
setTimeout(this.blah, 10);

setTimeout(function(){self.blah()}, 500);
//$(document).on('click', this.click);
console.log("---end--");

},

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

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




new p();

c = p.extend({"t": "wee"})


new c();


// This will not work:

x = p.extend({"a": "hahaha"})


0 comments on commit b8a97ec

Please sign in to comment.