Sha256: 95c53d7ba17d03c5066350be2b6a50cbd8c6143f0c9f0152b02a5e14cd63ede3

Contents?: true

Size: 1.02 KB

Versions: 100

Compression:

Stored size: 1.02 KB

Contents

/*!
 * Chai - addProperty utility
 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
 * MIT Licensed
 */

/**
 * ### addProperty (ctx, name, getter)
 *
 * Adds a property to the prototype of an object.
 *
 *     utils.addProperty(chai.Assertion.prototype, 'foo', function () {
 *       var obj = utils.flag(this, 'object');
 *       new chai.Assertion(obj).to.be.instanceof(Foo);
 *     });
 *
 * Can also be accessed directly from `chai.Assertion`.
 *
 *     chai.Assertion.addProperty('foo', fn);
 *
 * Then can be used as any other assertion.
 *
 *     expect(myFoo).to.be.foo;
 *
 * @param {Object} ctx object to which the property is added
 * @param {String} name of property to add
 * @param {Function} getter function to be used for name
 * @name addProperty
 * @api public
 */

module.exports = function (ctx, name, getter) {
  Object.defineProperty(ctx, name,
    { get: function () {
        var result = getter.call(this);
        return result === undefined ? this : result;
      }
    , configurable: true
  });
};

Version data entries

100 entries across 68 versions & 1 rubygems

Version Path
ende-0.4.25 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.25 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.24 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.24 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.23 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.23 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.5.1 components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.22 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.22 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.21 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.21 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.5.0 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.20 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.19 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.18 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.17 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.4.16 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.3.13 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.3.12 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js
ende-0.3.11 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js