mirror-js
Simple JavaScript reflection API.
I made this module for my personal use, but do not hesitate to leave your thoughts around here !
Installation
$ npm install mirror-js
Usage
var baseObj = {}; var mirror = ; var clone = ;
API
.clone()
Returns an exact copy of reflected object
var myObject = hello: 'Hello World !' { return thishello; } sub: { return 'Hi People !'; } ; copy = ; console; // Hello World !
.methods()
Returns a list of reflected object's methods
var myObject = hello: 'Hello World !' { return thishello; } sub: { return 'Hi People !'; } ; methods = ; console; // [sayHello]
.properties()
Returns a list of reflected object's properties
var myObject = hello: 'Hello World !' { return thishello; } sub: { return 'Hi People !'; } ; properties = ; console; // [hello, sub]
.prop()
Returns the value of a reflected object's property
var myObject = hello: 'Hello World !' { return thishello; } sub: { return 'Hi People !'; } ; property = ; console; // [Function]
.construct()
Returns reflected object's constructor
var myObject = hello: 'Hello World !' { return thishello; } ; const = constructor; console; // [Function]
.hasProperty()
Whether or not cloned object has a given property
var myObject = hello: 'Hello World !' { return thishello; } ; console; // trueconsole; // false
.hasMethod()
Whether or not cloned object has a given method
var myObject = hello: 'Hello World !' { return thishello; } ; console; // falseconsole; // true
.name()
Returns cloned object's name
var { thiscolor = color;}; Glassprototype = { return { return '...'; } }; console; // Glass
.parameters()
Return the parameters names of the given function.
var {}; console; // ['foo', 'bar', 'baz']
License
The MIT License (MIT)
Copyright (c) 2015 Arnaud PONEL
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.