-
ctor(pluginArr)
-
For creating a new instance of Scarlet
Parameters:
| Name |
Type |
Description |
pluginArr |
array
|
string
|
|
- Source:
Returns:
scarlet.lib.Scarlet
Example
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'
-
intercept(typeOrInstance, proxyType) → {scarlet.lib.Scarlet}
-
Method for proxying types, functions and instances
Parameters:
| Name |
Type |
Description |
typeOrInstance |
object
|
|
proxyType |
scarlet.lib.proxies.ProxyType
|
|
- Source:
Returns:
-
Type
-
scarlet.lib.Scarlet
Example
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);
-
load(pluginPath) → {scarlet.lib.Scarlet}
-
Method for loading a plugin into scarlet
Parameters:
| Name |
Type |
Description |
pluginPath |
String
|
|
- Source:
Returns:
-
Type
-
scarlet.lib.Scarlet
-
proxy() → {Object}
-
Method for retrieving a reference to a proxy type, this is for types that need to be instantiated using 'new'
- Source:
Returns:
-
Type
-
Object
-
using(callback) → {scarlet.lib.Scarlet}
-
Method for chaining interceptors onto a proxied type or function
Parameters:
| Name |
Type |
Description |
callback |
function
|
|
- Source:
Returns:
-
Type
-
scarlet.lib.Scarlet
Example
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);