Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

jsdi

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdi

DI - Dependency Injection , Inversion of Control - IoC , for JS.

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

DI

DI - Dependency Injection , Inversion of Control - IoC , for JS.

Install for node.js

npm install jsdi

Install for component

component install brighthas/jsdi

Example:

var DI = require("./index");
var Emitter = require("events").EventEmitter;

function User(){
    this.name = "brighthas";
}

User.prototype = {
    changeName:DI(function(name,my){
    
        var oldname = this.name;
        var newname = this.name = name;
        
        // publish change name event.
        my.emit("change name",{oldname:oldname,newname:newname});
        
    })
}


var emitter = new Emitter;
emitter.on("change name",function(data){
    console.log("old name is "+data.oldname);
    console.log("new name is "+data.newname);
});

// inject
User.prototype.my_ = emitter;

// test run 
var user = new User();
user.changeName("leo");

result is:

old name is brighthas
new name is leo

Keywords

DI

FAQs

Package last updated on 26 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts