Last active
August 29, 2015 14:05
-
-
Save salarkhan/7051633df8e04e25dc84 to your computer and use it in GitHub Desktop.
AJAX & OOJS
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
window.addEventListener( 'load', init ) | |
function init(){ | |
var controller = new Controller( new Model, new View ) | |
} | |
function Controller( model, view ){ | |
this.model = model | |
this.view = view | |
} | |
Controller.prototype = { | |
getArticles: function(){ | |
//the value of 'this' is the instance of the controller | |
$.ajax({ | |
url: '/articles', | |
type: 'get' | |
}).done( function( data ){ | |
//assuming the data we get back is fully-formed html | |
$('#article-container').append( data ) | |
//assuming the data we get back is JSON | |
var objects = JSON.parse( data ) | |
// if we don't bind, what's the value of this here? | |
this.view.render( objects ) | |
}.bind(this)) | |
}, | |
} | |
function View(){} | |
View.prototype = { | |
render: function( objects ){ | |
// whats the value of this here? | |
console.log( this ) | |
//loop through objects and do some shit where you append divs i dont know fuck | |
} | |
} | |
function Model(){} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment