mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Expand _.runInContext doc examples.
This commit is contained in:
16
lodash.js
16
lodash.js
@@ -854,22 +854,30 @@
|
|||||||
* @returns {Function} Returns a new `lodash` function.
|
* @returns {Function} Returns a new `lodash` function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.mixin({ 'add': function(a, b) { return a + b; } }, false);
|
* _.mixin({ 'add': function(a, b) { return a + b; } });
|
||||||
*
|
*
|
||||||
* var lodash = _.runInContext();
|
* var lodash = _.runInContext();
|
||||||
* lodash.mixin({ 'sub': function(a, b) { return a - b; } }, false);
|
* lodash.mixin({ 'sub': function(a, b) { return a - b; } });
|
||||||
*
|
*
|
||||||
* _.isFunction(_.add);
|
* _.isFunction(_.add);
|
||||||
* // => true
|
* // => true
|
||||||
*
|
|
||||||
* _.isFunction(_.sub);
|
* _.isFunction(_.sub);
|
||||||
* // => false
|
* // => false
|
||||||
*
|
*
|
||||||
* lodash.isFunction(lodash.add);
|
* lodash.isFunction(lodash.add);
|
||||||
* // => false
|
* // => false
|
||||||
*
|
|
||||||
* lodash.isFunction(lodash.sub);
|
* lodash.isFunction(lodash.sub);
|
||||||
* // => true
|
* // => 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) {
|
function runInContext(context) {
|
||||||
// Avoid issues with some ES3 environments that attempt to use values, named
|
// Avoid issues with some ES3 environments that attempt to use values, named
|
||||||
|
|||||||
@@ -12605,7 +12605,7 @@
|
|||||||
|
|
||||||
var lodash = _.runInContext(_.assign({}, root, {
|
var lodash = _.runInContext(_.assign({}, root, {
|
||||||
'Date': function() {
|
'Date': function() {
|
||||||
return { 'getTime': getTime, 'valueOf': getTime };
|
return { 'getTime': getTime };
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user