![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ES6 component for adjoining one function to another in an Aspect-Oriented style
Quality-controlled component for adjoining one function to another in an Aspect-Oriented style.
// ES6
import adjoin from "adjoin";
/**
* Start with an empty context to exemplify
*/
let context = {};
/**
* Start with a function that accepts zero or more arguments
*/
function originalFunction(argOne, argTwo) {
this.original = argOne;
// this.both was already set in beforeFunction
this.both = this.both + argTwo;
}
/**
* Create another function with the same
* arguments and optional callback.
*/
function beforeFunction(argOne, argTwo) {
this.before = argOne + 10;
this.both = argOne + argTwo;
}
/**
* Adjoin functions together into a new function
*/
const adjoinedFunction = adjoin.before(
originalFunction,
beforeFunction,
context
);
/**
* The adjoined function calls both functions
* in the correct order, with the specified
* arguments and context.
*/
adjoinedFunction(100, 200);
console.log(context); // {original:100, before:110, both:500}
Every build and release is automatically tested on the following platforms:
If your platform is not listed above, you can test your local environment for compatibility by copying and pasting the following commands into your terminal:
npm install adjoin
cd node_modules/adjoin
gulp test-local
Copy and paste the following command into your terminal to install Adjoin:
npm install adjoin --save
// ES6
import adjoin from "adjoin";
// ES5
var adjoin = require("adjoin");
// Require.js
define(["require"] , function (require) {
var adjoin = require("adjoin");
});
Adjoin.js takes two functions and adjoins then together to form a new function that calls both with the same arguments, in order.
There are currently two ways to adjoin one function to another:
adjoin.before(originalFunction, beforeFunction, [context])
adjoin.after(originalFunction, afterFunction, [context])
Both methods support asynchronous functions, and node-style asynchronous functions with a callback as the last argument.
Return an adjoinedFunction
that first calls beforeFunction
, then calls originalFunction
with the supplied arguments. Synchronous and node-style asynchronous functions are supported.
Synchronous Example:
// ES6
import adjoin from "adjoin";
/**
* Start with an empty context to exemplify
*/
let context = {};
/**
* Start with a function that accepts zero or more arguments
*/
function originalFunction(argOne, argTwo) {
this.original = argOne;
// this.both was already set in beforeFunction
this.both = this.both + argTwo;
}
/**
* Create another function with the same
* arguments and optional callback.
*/
function beforeFunction(argOne, argTwo) {
this.before = argOne + 10;
this.both = argOne + argTwo;
}
/**
* Adjoin functions together into a new function
*/
const adjoinedFunction = adjoin.before(
originalFunction,
beforeFunction,
context
);
/**
* The adjoined function calls both functions
* in the correct order, with the specified
* arguments and context.
*/
adjoinedFunction(100, 200);
console.log(context); // {original:100, before:110, both:500}
Node-style asynchronous Example:
// ES6
import adjoin from "adjoin";
/**
* Start with an empty context to exemplify
*/
let context = {};
/**
* Start with a function that accepts zero or
* more arguments, and optionally a callback
*/
function originalFunction(argOne, argTwo, callback) {
this.original = argOne;
this.both = argOne + argTwo;
callback();
}
/**
* Create another function with the same
* arguments and optional callback.
*/
function beforeFunction(argOne, argTwo, callback) {
this.before = argOne + 10;
// this.both was already set in originalFunction
this.both = this.both + argTwo;
callback();
}
/**
* Adjoin functions together into a new function
*/
const adjoinedFunction = adjoin.before(
originalFunction,
beforeFunction,
context
);
/**
* The adjoined function calls both functions
* in the correct order, with the specified
* arguments and context.
*/
adjoinedFunction(100, 200, () => {
console.log(context); // {original:100, before:110, both:500}
});
Return an adjoinedFunction
that first calls originalFunction
, then calls afterFunction
with the supplied arguments. Synchronous and node-style asynchronous functions are supported.
Synchronous Example:
// ES6
import adjoin from "adjoin";
/**
* Start with an empty context to exemplify
*/
let context = {};
/**
* Start with a function that accepts zero or more arguments
*/
function originalFunction(argOne, argTwo) {
this.original = argOne;
this.both = argOne + argTwo;
}
/**
* Create another function with the same
* arguments and optional callback.
*/
function afterFunction(argOne, argTwo) {
this.after = argOne + 10;
// this.both was already set in originalFunction
this.both = this.both + argTwo;
}
/**
* Adjoin functions together into a new function
*/
const adjoinedFunction = adjoin.after(
originalFunction,
afterFunction,
context
);
/**
* The adjoined function calls both functions
* in the correct order, with the specified
* arguments and context.
*/
adjoinedFunction(100, 200);
console.log(context); // {original:100, after:110, both:500}
Node-style asynchronous Example:
// ES6
import adjoin from "adjoin";
/**
* Start with an empty context to exemplify
*/
let context = {};
/**
* Start with a function that accepts zero or
* more arguments, and optionally a callback
*/
function originalFunction(argOne, argTwo, callback) {
this.original = argOne;
this.both = argOne + argTwo;
callback();
}
/**
* Create another function with the same
* arguments and optional callback.
*/
function afterFunction(argOne, argTwo, callback) {
this.after = argOne + 10;
// this.both was already set in originalFunction
this.both = this.both + argTwo;
callback();
}
/**
* Adjoin functions together into a new function
*/
const adjoinedFunction = adjoin.after(
originalFunction,
afterFunction,
context
);
/**
* The adjoined function calls both functions
* in the correct order, with the specified
* arguments and context.
*/
adjoinedFunction(100, 200, () => {
console.log(context); // {original:100, after:110, both:500}
});
See something that could use improvement? Have a great feature idea?
You can submit your ideas through our issues system, or make the modifications yourself and submit them to us in the form of a GitHub pull request.
We always aim to be friendly and helpful.
It's easy to run the test suite locally, and highly recommended if you're using Adjoin.js on a platform we aren't automatically testing for.
npm test
FAQs
ES6 component for adjoining one function to another in an Aspect-Oriented style
We found that adjoin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.