Skip to content

Instantly share code, notes, and snippets.

@haroldiedema
Last active August 29, 2015 14:02
Show Gist options
  • Save haroldiedema/52fb3f7345ab1ff8eabc to your computer and use it in GitHub Desktop.
Save haroldiedema/52fb3f7345ab1ff8eabc to your computer and use it in GitHub Desktop.
var WidgetInterface = Interface({
update: 'function'
});
/**
* Abstract Widget class.
*
* Instantiating this will result in an error because 'update'
* isn't implemented as defined in the interface.
*/
var Widget = Class({ implements: WidgetInterface }, {
__construct: function() {
// The Public API for a Widget.
return {
'update' : this.update
};
},
aBaseMethod: function() {
return 'Yay!';
}
});
/**
* Extending on Widget, doing something cool.
*/
var FooterWidget = Class({ extends: Widget }, {
/**
* @see WidgetInterface.update
*/
update: function()
{
// return twig stuff or whatever.
console.log(this.doStuff());
},
doStuff: function() {
// I am private!
return this.aBaseMethod() + ' I am private!';
}
});
var f = new FooterWidget();
// Only shows "update", as defined in the Public API declaration of the Widget class.
console.log(f);
f.update(); // prints: Yay! I am private!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment