Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

underscore-aop

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

underscore-aop

A fork of dojo/aspect that works w/ underscore-like libraries.

  • 0.5.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Underscore-AOP

An aop library that's compatible w/ the context bindings underscore.js and lodash.js.

Build Status

Overview

A lot of people use Aspect Oriented Programming (AOP) in JS. It's often called monkey-patching and can be exemplified w/ a common "pattern" I see rather frequently:

var originalMethod = obj[methodName];
obj[methodName] = function advisor () {
    // Do some stuff.
    return originalMethod.apply(this, arguments);
};

The key here is that the replaced reference modifies the behavior for all users of obj. However, if one of those users happens to do _.bind(obj[methodName], obj) before that aspect, then calls their bound function, it will not lead to advisor being called. This is because the bound function holds a pointer to the original function rather than the advisor.

To get around this, I'm aspecting _.bind, so that the newly created function will expose a private (as in it's mine, leave it alone) guid. Later, when the bound function is called, I look at all the methods on the calling context and figure out if there's an advisor that should be called instead of the original function.

Stability

Check out the tests for yourself. Seems ok to me, but I'm happy to look into the things I missed.

Objectives

I'm hoping to achieve/accomplish:

  • Provide before, after, and around support, that doesn't fork the pointer when _.bind has been called.
  • Provide support for almost any environment.
  • Provide reasonable performance.

Helping Out

If you want to help out, feel free to file pull requests.

To run the tests, ensure you have a recent version of NodeJS (>=0.8). Then, do:

git clone /path/to/your/fork
cd underscore-aop
npm install # npm comes w/ recent versions of node.
npm test # Should pass.

Please, ensure all current tests run and any new features have reasonable test coverage. (Checkout coverjs-gold if you're interested in this sorta thing.)

Keywords

FAQs

Package last updated on 17 Sep 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc