Last active
December 18, 2015 23:08
-
-
Save raganwald/5859117 to your computer and use it in GitHub Desktop.
This morning's "I made my very own WTF!?"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I'm in the middle of a method, and I decide that I'll use an | |
// Immediately Invoked Function Expression ("IIFE") to create a new | |
// block scope so that I don't have to pollute the entire thing with | |
// resultJSON and contentJSON variables that would otherwise get | |
// hoisted. | |
// | |
// The current object DOES have a toJSON method, and so does the object called content. | |
// _.isFunction(this.toJSON) ==> true | |
// _.isFunction(content.toJSON) => true | |
� | |
return (function () { | |
var resultJSON = this.toJSON(), | |
contentJSON = content.toJSON(); | |
_.each(contentJSON, function (contentRow, rowIndex) { | |
var resultRow = resultJSON[extant + upperLeft.y + rowIndex]; | |
_.each(contentRow, function (contentCell, columnIndex) { | |
resultRow[extant + upperLeft.x + columnIndex] = contentCell; | |
}); | |
}); | |
return QuadTree.fromJSON(resultJSON); | |
})(); | |
// So what happens? | |
// TypeError: Cannot call method 'toJSON' of undefined | |
// Investigation reveals that the offending line is 14, | |
// "resultJSON = this.toJSON()" | |
// | |
// WTF!? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Passing
this
tothat
works, as did: