Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/benjamingr/interface-js
- Owner: benjamingr
- Created: 2013-06-15T17:25:40.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-06-21T19:52:54.000Z (over 11 years ago)
- Last Synced: 2024-10-19T05:01:54.389Z (19 days ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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?)