Responder
Object that holds 'status' & 'response'
by Abhishek Kumar
HTML
<div id="konsole">
</div>
JavaScript
var Responder = {
struct: {
status: null,
response: null
},
set: function(s, d) {
var o = this.struct;
o.status = s;
o.response = d;
},
get: function() {
return this.struct;
},
success: function(d) {
this.set(true, d);
},
failure: function(d) {
this.set(false, d);
}
};
var konsole = document.getElementById('konsole');
var log = function (s) {
konsole.innerHTML += s + '\n';
}
// Pass
Responder.success('hello1')
log(JSON.stringify(Responder.get()));
/*
// Fail
var responder = new Responder;
responder.failure('hello1')
log(JSON.stringify(responder.get()));
*/