Last active
August 29, 2015 14:02
-
-
Save haroldiedema/52fb3f7345ab1ff8eabc to your computer and use it in GitHub Desktop.
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
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