Skip to content

Instantly share code, notes, and snippets.

@salarkhan
Last active August 29, 2015 14:05
Show Gist options
  • Save salarkhan/7051633df8e04e25dc84 to your computer and use it in GitHub Desktop.
Save salarkhan/7051633df8e04e25dc84 to your computer and use it in GitHub Desktop.
AJAX & OOJS
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