Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 1.09 KB

.verb.md

File metadata and controls

61 lines (47 loc) · 1.09 KB

Usage

var delegate = require('{%= name %}');
delegate(receiver, provider, clone);

Params

  • receiver: (Object) The object receiving properties
  • provider: (Object) The object providing properties

Examples

copy properties

Copy properties and make them non-enumerable

var provider = {
  upper: function(val) {
    return val.toUpperCase();
  },
  lower: function(val) {
    return val.toLowerCase();
  }
};

var receiver = {};
// an existing properties in the `receiver` 
// object would be overwritten
delegate(receiver, provider);

receiver.upper('foo');
receiver.lower('BAR');

console.log(receiver.upper('foo')); // 'FOO' 
console.log(receiver.lower('BAR')); // 'bar'

// copied properties are non-enumerable
console.log(receiver); // {}
console.log(Object.keys(receiver)); // []

make existing properties non-enumerable

var obj = {
  upper: function(val) {
    return val.toUpperCase();
  },
  lower: function(val) {
    return val.toLowerCase();
  }
};

delegate(obj);
console.log(obj) // {}
obj.upper('foo') // 'FOO'
obj.lower('BAR') // 'bar'