0.0.4 • Published 9 years ago

ifjs v0.0.4

Weekly downloads
14
License
-
Repository
github
Last release
9 years ago

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

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago