copy-descriptor
Copy a descriptor from object A to object B
Last updated 8 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install copy-descriptor 
SYNC missed versions from official npm registry.

copy-descriptor NPM version NPM downloads Build Status

Copy a descriptor from object A to object B

Install

Install with npm:

$ npm install copy-descriptor --save

Usage

var copy = require('copy-descriptor');

API

copy

Copy a descriptor from one object to another.

Params

  • receiver {Object}: The target object
  • provider {Object}: The provider object
  • from {String}: The key to copy on provider.
  • to {String}: Optionally specify a new key name to use.
  • returns {Object}

Example

function App() {
  this.cache = {};
}
App.prototype.set = function(key, val) {
  this.cache[key] = val;
  return this;
};
Object.defineProperty(App.prototype, 'count', {
  get: function() {
    return Object.keys(this.cache).length;
  }
});

copy(App.prototype, 'count', 'len');

// create an instance
var app = new App();

app.set('a', true);
app.set('b', true);
app.set('c', true);

console.log(app.count);
//=> 3
console.log(app.len);
//=> 3

Related projects

You might also be interested in these projects:

Contributing

This document was generated by verb-readme-generator (a verb generator), please don't edit directly. Any changes to the readme must be made in .verb.md. See Building Docs.

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. Or visit the verb-readme-generator project to submit bug reports or pull requests for the readme layout template.

Building docs

Generate readme and API documentation with verb:

$ npm install -g verb verb-readme-generator && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on June 09, 2016.

Current Tags

  • 0.1.1                                ...           latest (8 years ago)

2 Versions

  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |