Created
July 3, 2013 03:03
-
-
Save angelochen960/5915127 to your computer and use it in GitHub Desktop.
Interface for javascript
This file contains hidden or 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
// https://docs.google.com/presentation/d/1dp0GOtvl2-pZoxkyzvGvq5zmPdMIDQIBzr2Vv_3JzQo/pub?start=false&loop=false&delayms=3000#slide=id.gd2fff574_099 | |
// Clients is an interface | |
var Clients = { | |
get : function(id) {}, | |
save : function(client) {}, | |
list : function() {}, | |
msg : function() {} | |
} | |
function consummer(clients) { | |
console.log(clients.msg()) | |
} | |
// implement the interface | |
var ClientsImpl = function(n) { | |
this.name = n | |
return this; | |
} | |
ClientsImpl.prototype = Object.create(Clients) | |
ClientsImpl.prototype.msg = function() {return 'abc'} | |
consummer(Clients) | |
var sup = new ClientsImpl('test1') | |
consummer(sup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment