https://github.com/prettymuchbryce/imp
Interfaces in JavaScript.
https://github.com/prettymuchbryce/imp
Last synced: about 1 year ago
JSON representation
Interfaces in JavaScript.
- Host: GitHub
- URL: https://github.com/prettymuchbryce/imp
- Owner: prettymuchbryce
- License: mit
- Created: 2013-08-26T23:07:35.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-09-04T20:56:05.000Z (almost 13 years ago)
- Last Synced: 2025-04-13T16:56:59.863Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 105 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# imp.js
> Interfaces in JavaScript.
#### About
Interfaces are a common OOP tool in languages like Java. Imp offers a solution for using interfacing in Javascript. Imp checks method names, and parameter names. Imp throws runtime errors if your classes fail to properly implement their interfaces.
#### Defining an interface
var IAnimal =
{
"methods": [
{ "name" : "makeSound", "params": ["sound"] },
{ "name" : "isMammal" },
{ "name" : "isDomestic" }
]
}
#### Ensuring a class implements this interface
var Dog = function() {
Imp.lements(IAnimal, this);
this.makeSound = function(sound) {
console.log("Woof!" + sound);
};
this.isMammal = function() {
return true;
};
this.isDomestic = function() {
return true;
};
};
#### API Recap
`Imp.lements(interfaceReference, implementation);`
`Imp.doesImplement(interfaceReference, implementation);`
`Imp.setProductionMode(); //Remove interface enforcement and console errors.`
## Want to learn more?
_Find the minified file in the bin directory._
**See example.html for a more robust example**