Skip to content

Instantly share code, notes, and snippets.

@f3r
Last active August 29, 2015 14:15
Show Gist options
  • Save f3r/e08bbfa5945acd10d278 to your computer and use it in GitHub Desktop.
Save f3r/e08bbfa5945acd10d278 to your computer and use it in GitHub Desktop.
Binding Behaviour quiz :)
loggest('Let\'s get the party STARTED');
function loggest(txt){
var length = (txt.length + 2);
if (length > 80) { length = 80 };
console.log(txt); console.log(new Array(length + 2).join('-'));
}
function bindBehavior(config) {
return function(obj) {
loggest('Executing bindBehavior');
console.log('this=' + this);
console.log('a=' + a);
console.log('b=' + b);
console.log('obj=' + obj.a);
console.log('obj=' + obj.b);
console.log('obj1=' + obj1);
console.log('obj2=' + obj2);
console.log('config=' + config);
loggest('config.flag=' + config.flag);
}
}
loggest('Define a'); var a = bindBehavior({flag: 'flag_RTFM'});
loggest('Define b'); var b = bindBehavior({flag: 'flat_YOLO'});
var obj1 = {a: 'first object'};
var obj2 = {b: 'second object'};
loggest('Call a(obj1)'); a(obj1);
loggest('Call b(obj2)'); b(obj2);
loggest('Call a(obj2)'); a(obj2);
loggest('Call b(obj1)'); b(obj1);
loggest('The END :)');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment