Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/benjamingr/interface-js

JavaScript Interfaces with Harmony proxies
https://github.com/benjamingr/interface-js

Last synced: 4 days ago
JSON representation

JavaScript Interfaces with Harmony proxies

Awesome Lists containing this project

README

        

Interface JS
----

JavaScript interfaces implemented through Harmony proxies or ES5 getters (weaker).
Enforce contracts in JavaScript!

Usage:
----

//Define an interface
var Iface = Interface(function(){
this.foo =function(x){};
});

//Define an implementor
function Impl(){
this.foo = function(x,y){}
this.y=10;
}

var a = new Impl(); //Instantiate the object

var b = Iface(a); // Observe it like an interface implementor

b.y;//undefined - access to unknown property

b.foo;//returns b's foo, perfectly OK

In the above example, had we passed an object that does not implement a method `foo`, or implemeted
such a method with fewer parameters an execption would have been raised.

Use either interfacees5.js (if you need to support ES5 implementations) or interface.js if you only
need to support harmony implementations.

Todo

- ---Get it working!---
- ---Allow optional typing---
- ---Allow debug/production modes where production does not use actual proxies---
- Allow type checking to occur once or on every access
- Allow interface inheritance (maybe?)