Skip to content

Instantly share code, notes, and snippets.

@angelochen960
Created July 3, 2013 03:03
Show Gist options
  • Save angelochen960/5915127 to your computer and use it in GitHub Desktop.
Save angelochen960/5915127 to your computer and use it in GitHub Desktop.
Interface for javascript
// 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