ReflectionJS
Although there are no classes in JavaScript, therefore the term "reflection" wouldn't be very accurate, this is an attempt to bring some of the features from languages like C# and Java to JavaScript.
Getting Started
Install the module with: npm install --save reflectionjs
var reflection = ;
Documentation
call(functionName, [args])
Execute a function by name.
var obj = { console; } { return a + b; }; ; // "it works!"; // 10
clone()
Creates an exact copy of the object without keeping a reference to it.
var obj = a: "a"; var copy = ;copya = "b"; console; // "a"console; // "b"
get(propertyName)
Returns a reference to a property. Also accepts a namespace as argument like "my.cool.namespace"
.
var obj = name: "jose" company: name: "Reflectors Inc" { console; }; var ref; ref = ;console; // "jose" ref = ;console; // "Reflectors Inc"
You can also run methods like:
ref = ;; // "jose"
methods()
Returns an array with all methods names. In this case, properties are ignored.
var obj = name: "jose" { console; } { console; }; var methods = ;console; // ["print", "sayHello"]
owns(propertyName)
Check if the object owns a property. Also accepts a namespace as argument like "my.cool.namespace"
.
var obj = name: "jose" company: name: "Reflectors Inc" ; ; // true; // true; // false
properties()
Returns an array with all properties names. In this case, methods are ignored.
var obj = name: "jose" age: 32 { console; }; var properties = ;console; // ["name", "age"]
set(propertyName, value)
Sets a property value. If the property does not exists, it will be created, even if it is an nested property.
Also accepts a namespace as argument like "my.cool.namespace"
.
var obj = name: "jose" company: name: null ; ;console; // "bob" ;console; // "Reflectors Inc" ;console; // "www.getreflectors.com"
type()
Returns a string containing the type of the current object.
var obj = {}; var type; type = type;console; // "Object" type = type;console; // "Null" type = type;console; // "Number" type = type;console; // "RegExp"