]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/node_modules/es6-weak-map/node_modules/d/auto-bind.js
1b00dba3cc3ddf764db83608d66d03a6ea7a60ed
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / node_modules / es6-weak-map / node_modules / d / auto-bind.js
1 'use strict';
2
3 var copy = require('es5-ext/object/copy')
4 , map = require('es5-ext/object/map')
5 , callable = require('es5-ext/object/valid-callable')
6 , validValue = require('es5-ext/object/valid-value')
7
8 , bind = Function.prototype.bind, defineProperty = Object.defineProperty
9 , hasOwnProperty = Object.prototype.hasOwnProperty
10 , define;
11
12 define = function (name, desc, bindTo) {
13 var value = validValue(desc) && callable(desc.value), dgs;
14 dgs = copy(desc);
15 delete dgs.writable;
16 delete dgs.value;
17 dgs.get = function () {
18 if (hasOwnProperty.call(this, name)) return value;
19 desc.value = bind.call(value, (bindTo == null) ? this : this[bindTo]);
20 defineProperty(this, name, desc);
21 return this[name];
22 };
23 return dgs;
24 };
25
26 module.exports = function (props/*, bindTo*/) {
27 var bindTo = arguments[1];
28 return map(props, function (desc, name) {
29 return define(name, desc, bindTo);
30 });
31 };