npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

javascript-oop-aop-ioc

v1.0.6

Published

Easily Javascript OOP, AOP, IoC Library

Downloads

9

Readme

Image

Javascript-OOP-AOP-IoC

Easily Javascript OOP Library

travis build results

Install

  • npm
npm install javascript-oop-aop-ioc
  • bower
bower install javascript-oop-aop-ioc
  1. Basic =========

We can learn to define the classes so easily. oop.class(...) method is it.

oop.class( [parents,] classInfo )

  1. Define class.

    var Program = oop.class({
        say: function() { return "Hello"; }
    });
    
    var p = new Program();
    p.say();
    
    // return "Hello"
  2. Define properties.

    • Define basically properties.

      // Define class.
      var Program = oop.class({
      	say: function() { return "Hello"; },
      	name: "엄준일"
      });
        
      var p = new Program();
      console.log("My name is ", p.name);
        
      // output
      My name is 엄준일
    • Define custom get/set property.

      var Program = oop.class({
      	say: function() { return "Hello"; },
      	name: "엄준일",
      	age: { get: function()      { return this._age; },
      		   set: function(value) { this._age = value; }
      });
        
      var p = new Program();
      p.age = 35;
      console.log("My age is ", p.age);
        
      // output
      My age is 35
  3. Inheritances ================

oop.class( parents, classInfo )

  1. Inheritance from parent.

    // Define parent class
    var Program = oop.class({
    	version: "1.0.2",
    	show: function() { 
        	console.log("openning window."); 
            /* some code.. */
        }
    });
       
    // Define class.
    var Outlook = oop.class( Program, {
    	run: function() { console.log("running outlook program."); }
    });
       
    // Run code.
    var outlook = new Outlook();
    console.log("version " + outlook.version);
    outlook.run();
    outlook.show();
       
    // Output
    version 1.0.2
    running outlook program.
    openning window.
  2. 'self' instance reference.

    var Program = oop.class({
    	version: "1.0.2",
    	show: function() { 
        	console.log("openning window.");
            /* some code.. */ }
    });
       
    var Outlook = oop.class( Program, {
    	run: function(self) { // inject 'self' argument name.
        	console.log("running outlook program.");
               
            // *** HERE ***
            // a method call inhertianced Program.show method.
            self.show();
        }
    });
       
    var outlook = new Outlook();
    console.log("version " + outlook.version);
    outlook.run();
    //outlook.show();      remove this line.
       
    // Output
    version 1.0.2
    running outlook program.
    openning window.
  3. 'base' parent instance reference.

    var Program = oop.class({
        run: function() { console.log("run Program.") }
    });
    
    var Outlook = oop.class( Program, { // HERE inheritance Program class.
        run: function(base) { 
            console.log("run Outlook.");  
    
            // *** HERE ***
            // You can call parent method from base keyword.
            base.run();
        }
    });
    
    // Output
    // run Outlook.
    // run Program.
  4. Hierarchically Inheritances.

    var Program = oop.class( { 
    	run: function() { console.log("Program.run();");  
    }});
    var ProgramBase = oop.class( Program, { 
    	run: function(base) { console.log("ProgramBase.run();"); base.run();
    }});
    var Outlook = oop.class( ProgramBase, { 
    	run: function(base) { console.log("Outlook.run();"); base.run(); 
    }});
       
    var outlook = new Outlook();
    outlook.run();
       
    // Output
    Outlook.run();
    ProgramBase.run();
    Program.run(); 
  5. Injection =============

oop.inject( [argument], ... )

  1. Inject to pass arguments.

     var Program = oop.class({
    	version: "v1.0"
     });
        
     var Outlook = oop.class( Program, {
     	version: "v2.0",
     	run: function(base, self) { 
        	console.log("base version: "   , base.version)
        	console.log("current version: ", self.version);
        }
     });
        
     var outlook = new Outlook();
     outlook.run();
        
     // Output
     base version: v1.0
     current version: v2.0
  2. Inject to resolve container.

  3. Interception - AOP ======================

  • oop.interception( function, behavior )

  • oop.interceptionBehavior( before, after, exception, finally_ )

  1. Interception a class or method.

    • Interception a method

      var Program = oop.class({
          run: function(msg) { console.log("run Program. ", msg); }
      });
      
      // *** HERE ***
      // Setup the interception a method
      var p = new Program();
      oop.interception( p.run, oop.behaviors.LoggingBehavior );
      
      // Call a 'run' method.
      p.run("Now running...");
      
      // Output
      ------ enter interception ------
      [Thu Nov 13 2014 09:29:41 GMT+0900 (KST)]  {}
      run Program.  Now running...
      ------ end interception ------
    • Interception a class instance.

      var Program = oop.class({
          run: function(msg)       { console.log("run Program.", msg); },
          terminate: function() { console.log("Terminated the Program.") }
      });
      
      // *** HERE ***
      // Pass class instance arguments
      var p = new Program();
      oop.interception( p, oop.behaviors.LoggingBehavior );
      
      // Call a 'run' method.
      p.run("Now running...");
      p.terminate();
      
      // Output
      ------ enter interception ------
      [Thu Nov 13 2014 09:29:41 GMT+0900 (KST)]  {}
      run Program.  Now running...
      Terminated the Program.
      ------ end interception ------
  2. Interception custom behaviors

    • Define the custom behavior

      You can make the interception behaviors, call the oop.interceptionBehavior method.

    var customBehavior = oop.interceptionBehavior(
    	function() { console.log("before"); },
    	function() { console.log("after"); },
    	function() { console.log("throw exception"); },
    	function() { console.log("finally"); }
    );
       
    var Program = oop.class({
    	run: function() { console.log("run Program."); }
    });
       
    var p = new Program();
    oop.interception(p,  customBehavior);
    p.run();
       
    // Output
    before
    run Program.
    after
    finally

    If it throw the exception, invoke exception behavior. For examples,

    var Program = oop.class({
        run: function() { 
        	console.log("run Program."); 
            throw "crashing... "; 
     }});
       
    var p = new Program();
    oop.interception(p,  customBehavior);
    p.run();
       
    // Output
    before
    run Program.
    throw exception crashing...   // HERE exception behavior.
    finally