UNPKG

scarlet

Version:

The simple fast javascript interceptor for methods and properties.

850 lines (303 loc) 9.35 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Global</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Global</h1> <section> <header> <h2> </h2> </header> <article> <div class="container-overview"> <dl class="details"> </dl> </div> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="ctor"><span class="type-signature"></span>ctor<span class="signature">(pluginArr)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> For creating a new instance of Scarlet </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>pluginArr</code></td> <td class="type"> <span class="param-type">array</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="scarlet.js.html">/usr/local/src/nodejs/scarlet/lib/scarlet.js</a>, <a href="scarlet.js.html#line3">line 3</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> scarlet.lib.Scarlet </div> <h5>Example</h5> <pre class="prettyprint"><code> var Scarlet = require("scarlet"); var scarlet = new Scarlet(); // A function that does addition function add(arg1, arg2){ return arg1 + arg2; } // Log arguments and result of add add = scarlet .intercept(add, scarlet.FUNCTION) .using(function(info, method, args){ console.log("Adding '" + args[0] + "'' and '" + args[1] + "'"); var result = method.call(this, info, method, args); console.log("Result is '" + result + "'"); return result; }).proxy(); add(1,2); // Output -> Adding '1' and '2'\n Result is '3' add(3,5); // Output -> Adding '3' and '5'\n Result is '8'</code></pre> </dd> <dt> <h4 class="name" id="intercept"><span class="type-signature"></span>intercept<span class="signature">(typeOrInstance, proxyType)</span><span class="type-signature"> &rarr; {scarlet.lib.Scarlet}</span></h4> </dt> <dd> <div class="description"> Method for proxying types, functions and instances </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>typeOrInstance</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>proxyType</code></td> <td class="type"> <span class="param-type">scarlet.lib.proxies.ProxyType</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="scarlet.js.html">/usr/local/src/nodejs/scarlet/lib/scarlet.js</a>, <a href="scarlet.js.html#line143">line 143</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">scarlet.lib.Scarlet</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>var Scarlet = require("scarlet"); var scarlet = new Scarlet(); // Type for that we would like to intercept function MyClass(){ var self = this; self.myMethod = function(arg1, arg2){ return arg1 + arg2; }; } // First instantiate the type var instance = new MyClass(); // Scarlet will only intercept the instance instance = scarlet .intercept(instance, scarlet.INSTANCE) .using(function(info, method, args){ return method.call(this, info, method, args); }).proxy(); // Invoke var result = instance.myMethod(1,2);</code></pre> </dd> <dt> <h4 class="name" id="load"><span class="type-signature"></span>load<span class="signature">(pluginPath)</span><span class="type-signature"> &rarr; {scarlet.lib.Scarlet}</span></h4> </dt> <dd> <div class="description"> Method for loading a plugin into scarlet </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>pluginPath</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="scarlet.js.html">/usr/local/src/nodejs/scarlet/lib/scarlet.js</a>, <a href="scarlet.js.html#line284">line 284</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">scarlet.lib.Scarlet</span> </dd> </dl> </dd> <dt> <h4 class="name" id="proxy"><span class="type-signature"></span>proxy<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4> </dt> <dd> <div class="description"> Method for retrieving a reference to a proxy type, this is for types that need to be instantiated using 'new' </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="scarlet.js.html">/usr/local/src/nodejs/scarlet/lib/scarlet.js</a>, <a href="scarlet.js.html#line272">line 272</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> </dd> <dt> <h4 class="name" id="using"><span class="type-signature"></span>using<span class="signature">(callback)</span><span class="type-signature"> &rarr; {scarlet.lib.Scarlet}</span></h4> </dt> <dd> <div class="description"> Method for chaining interceptors onto a proxied type or function </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="scarlet.js.html">/usr/local/src/nodejs/scarlet/lib/scarlet.js</a>, <a href="scarlet.js.html#line188">line 188</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">scarlet.lib.Scarlet</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>var Scarlet = require("scarlet"); var scarlet = new Scarlet(); // Type for that we would like to intercept function MyClass(){ var self = this; self.myMethod = function(arg1, arg2){ return arg1 + arg2; }; } // First instantiate the type var instance = new MyClass(); // Scarlet will only intercept the instance instance = scarlet .intercept(instance, scarlet.INSTANCE) .using(function(info, method, args){ // Interceptor 1 return method.call(this, info, method, args); }) .using(function(info, method, args){ // Interceptor 2 return method.call(this, info, method, args); }) .using(function(info, method, args){ // Interceptor 3 return method.call(this, info, method, args); }).proxy(); // Invoke var result = instance.myMethod(1,2);</code></pre> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Global</h3><ul><li><a href="global.html#ctor">ctor</a></li><li><a href="global.html#intercept">intercept</a></li><li><a href="global.html#load">load</a></li><li><a href="global.html#proxy">proxy</a></li><li><a href="global.html#using">using</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Mon Dec 30 2013 00:28:21 GMT+0000 (GMT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>