Expand _.runInContext doc examples.

This commit is contained in:
John-David Dalton
2015-01-05 17:45:24 -08:00
parent 59070bcd5b
commit bb2f1aa4be
2 changed files with 13 additions and 5 deletions

View File

@@ -854,22 +854,30 @@
* @returns {Function} Returns a new `lodash` function.
* @example
*
* _.mixin({ 'add': function(a, b) { return a + b; } }, false);
* _.mixin({ 'add': function(a, b) { return a + b; } });
*
* var lodash = _.runInContext();
* lodash.mixin({ 'sub': function(a, b) { return a - b; } }, false);
* lodash.mixin({ 'sub': function(a, b) { return a - b; } });
*
* _.isFunction(_.add);
* // => true
*
* _.isFunction(_.sub);
* // => false
*
* lodash.isFunction(lodash.add);
* // => false
*
* lodash.isFunction(lodash.sub);
* // => true
*
* // using `context` to mock `Date#getTime` use in `_.now`
* var mock = _.runInContext({
* 'Date': function() {
* return { 'getTime': getTimeMock };
* }
* });
*
* // or creating a suped-up `defer` in Node.js
* var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
*/
function runInContext(context) {
// Avoid issues with some ES3 environments that attempt to use values, named

View File

@@ -12605,7 +12605,7 @@
var lodash = _.runInContext(_.assign({}, root, {
'Date': function() {
return { 'getTime': getTime, 'valueOf': getTime };
return { 'getTime': getTime };
}
}));