Created
March 5, 2014 17:06
-
-
Save khamiltonuk/9371531 to your computer and use it in GitHub Desktop.
Understanding This
This file contains hidden or 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
| // Bad | |
| var myObj = { | |
| specialFunction: function () { | |
| }, | |
| anotherSpecialFunction: function () { | |
| }, | |
| getAsyncData: function (cb) { | |
| cb(); | |
| }, | |
| render: function () { | |
| var that = this; | |
| this.getAsyncData(function () { | |
| that.specialFunction(); | |
| that.anotherSpecialFunction(); | |
| }); | |
| } | |
| }; | |
| myObj.render(); | |
| // Good | |
| var myObj = { | |
| specialFunction: function () { | |
| // Statements | |
| console.log('hello1'); | |
| }, | |
| anotherFunction: function () { | |
| // Statements | |
| console.log('hello2'); | |
| }, | |
| getAsyncData: function (cb) { | |
| // Statements | |
| console.log('hello3'); | |
| cb(); | |
| }, | |
| render: function () { | |
| this.getAsyncData(function(){ | |
| this.specialFunction(); | |
| this.anotherFunction(); | |
| }.bind(this)); | |
| } | |
| }; | |
| myObj.render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment