LoginSignup
6

More than 5 years have passed since last update.

Node で AMD っぽく DI できる fount を使ってみる

Last updated at Posted at 2014-07-25

npm で インストールします。

npm install fount -S

fount を require します。

var fount = require('fount');

まずは、簡単な文字列で登録してみます。

fount.register('library', 'fount');
fount.register('mySaying', 'ええわ!');

dependencies を指定しての登録もできます。

fount.register('say', ['library', 'mySaying'], function (library, mySaying) {
  return function () { console.log(library + mySaying); };
});

それを inject して say 関数を使います。

fount.inject(['say'], function (say) {
  say(); // fountええわ!
});

AMD っぽく DI できました!

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6