@kingjs/reflect.define-accessor
v1.0.2
Published
Extends `kingjs/reflect.define-property` with richer overloads.
Downloads
3
Readme
@kingjs/reflect.define-accessor
Extends kingjs/reflect.define-property
with richer overloads.
Usage
var assert = require('assert');
var defineFunction = require('@kingjs/reflect.define-accessor');
var target = defineFunction({ bar: 1 },
function foo() { return this.bar; },
function(value) { return this.bar = value; }
);
assert(target.foo == 1);
target.foo = 2;
assert(target.bar == 2);
assert(target.propertyIsEnumerable('foo'));
var target = defineFunction({ bar: 1 }, 'foo',
function() { return this.bar; },
function(value) { this.bar = value; }
);
assert(target.foo == 1);
target.foo = 2;
assert(target.bar == 2);
assert(target.propertyIsEnumerable('foo'));
var target = defineFunction({ bar: 1 }, 'foo',
'this.bar',
'this.bar = value'
);
assert(target.foo == 1);
target.foo = 2;
assert(target.bar == 2);
assert(target.propertyIsEnumerable('foo'));
API
defineAccessor(target, name, descriptor)
Overloads
defineAccessor(target, get[, set])
=> defineProperty(target, get.name || set.name, { get, set });
defineAccessor(target, name, get[, set])
=> defineProperty(target, name, { get, set });
defineAccessor(target, name, string[, string])
=> defineProperty(target, name, { get: lambda, set: lambda });
// inherited from @kingjs/reflect.define-property
defineAccessor(...)
=> defineProperty(...);
Parameters
target
: The target on which the property will be defined.name
: The name of the property.descriptor
: A descriptor describing the property.
Install
With npm installed, run
$ npm install @kingjs/reflect.define-accessor
Dependencies
|Package|Version|
|---|---|
|@kingjs/is
|^1.0.9
|
|@kingjs/reflect.define-property
|^1.0.2
|
Source
https://repository.kingjs.net/reflect/define-accessor
License
MIT