ifjs

0.0.4 • Public • Published

ifjs

Native implementation of interfaces for js

npm Build Status Code Climate Dependency Status Build Status

Simple Example

To describe the parameters or return values so you can use native js types (except null and undefined).

var ICalc = new Interface('ICalc', { sum: {args: [Number, Number], result: Number},
        dif: {args: [Number, Number], result: Number} });
 
var IStringConcat = new Interface('IStringConcat', { concat: {args: [String, String], result: String} });
 
var IMatch = new Interface('IMatch', { match: {args: [RegExp], result: Boolean} });

In addition, in the description of the arguments to a function in the interface (or return values) can be used a constructor function, for example:

function F() {}
F.prototype.fn = function() { return '\' nruter } ()noitcnuf = nf.epytotorp.F'; }
 
var IFClient = new Interface('IFClient', {
  run: [F]
});
 
function FClient() {}
 
Class(FClient, null, [IFClient], {
  run: function(obj) {
    console.log(obj.fn());
  };
});
 
var f = new F();
var fclient = new FClient();
 
fclient.run(f);

can pass as an interface object, not wrapped new Interface(...)

Class({}, null, [{ fn: [] }], { fn: function() { return 'Yes, we can!'; } });

If you pass only one interface, you can omit the brackets "[...]".

Class({}, null, { fn: { args: [], result: String } },
    { fn: function() { return '1234567890'; } });

More examples are in Russian localization.

Bitdeli Badge

Readme

Keywords

none

Package Sidebar

Install

npm i ifjs

Weekly Downloads

2

Version

0.0.4

License

none

Last publish

Collaborators

  • swvitaliy