Coder Social home page Coder Social logo

meld's Introduction

Build Status

Aspect Oriented Programming for Javascript. It allows you to change the behavior of, or add behavior to methods and functions (including constructors) non-invasively.

As a simple example, instead of changing code, you can use meld to log the result of myObject.doSomething:

var myObject = {
	doSomething: function(a, b) {
		return a + b;
	}
};

// Call a function after myObject.doSomething returns
var remover = meld.after(myObject, 'doSomething', function(result) {
	console.log('myObject.doSomething returned: ' + result);
});

myObject.doSomething(1, 2); // Logs: "myObject.doSomething returned: 3"

remover.remove();

myObject.doSomething(1, 2); // Nothing logged

Docs

Quick Start

AMD

  1. Get it using one of the following

    1. yeoman install meld, or
    2. bower install meld, or
    3. git clone https://github.com/cujojs/meld, or
    4. git submodule add https://github.com/cujojs/meld
  2. Configure your loader with a package:

    packages: [
    	{ name: 'meld', location: 'path/to/meld', main: 'meld' },
    	// ... other packages ...
    ]
  3. define(['meld', ...], function(meld, ...) { ... }); or require(['meld', ...], function(meld, ...) { ... });

Node

  1. npm install meld
  2. var meld = require('meld');

RingoJS

  1. ringo-admin install cujojs/meld
  2. var meld = require('meld');

Running the Unit Tests

Install buster.js

npm install -g buster

Run unit tests in Node:

buster test

What's New

1.3.0

  • meld() is now a function that adds aspects.
    • DEPRECATED: meld.add(). Use meld() instead.

1.2.2

  • Remove stray console.log.

1.2.1

  • Fix for IE8-specific issue with meld's internal use of Object.defineProperty.
  • Internally shim Object.create if not available to so that meld no longer requires an Object.create shim to advise constructors in pre-ES5 environments.

1.2.0

  • meld.joinpoint() - Access the current joinpoint from any advice type.
  • Bundled aspects:
    • trace: trace method call entry/return/throw
    • memoize: simple memoization for methods and functions
    • cache: configurable caching aspect to do more than simple memoization

1.1.0

  • Advice can be applied directly to methods on a function.
  • Removed undocumented behavior that implicitly adds constructor prototype advice: to advise a prototype, pass the prototype as the advice target.

1.0.0

See the full Changelog here

References

meld's People

Contributors

briancavalier avatar scothis avatar brandonaaron avatar jasonkarns avatar unscriptable avatar foxdonut avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.