mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Add imports option docs to _.template.
Former-commit-id: 4ac5d64b0dae3068d07474beabed7fd5702da9a2
This commit is contained in:
31
dist/lodash.underscore.js
vendored
31
dist/lodash.underscore.js
vendored
@@ -451,7 +451,7 @@
|
||||
|
||||
function bound() {
|
||||
// `Function#bind` spec
|
||||
// http://es5.github.com/#x15.3.4.5
|
||||
// http://es5.github.io/#x15.3.4.5
|
||||
var args = arguments,
|
||||
thisBinding = isPartial ? this : thisArg;
|
||||
|
||||
@@ -468,7 +468,7 @@
|
||||
thisBinding = createObject(func.prototype);
|
||||
|
||||
// mimic the constructor's `return` behavior
|
||||
// http://es5.github.com/#x13.2.2
|
||||
// http://es5.github.io/#x13.2.2
|
||||
var result = func.apply(thisBinding, args);
|
||||
return isObject(result) ? result : thisBinding;
|
||||
}
|
||||
@@ -1056,8 +1056,8 @@
|
||||
otherType = typeof b;
|
||||
|
||||
if (a === a &&
|
||||
(!a || (type != 'function' && type != 'object')) &&
|
||||
(!b || (otherType != 'function' && otherType != 'object'))) {
|
||||
!(a && objectTypes[type]) &&
|
||||
!(b && objectTypes[otherType])) {
|
||||
return false;
|
||||
}
|
||||
if (a == null || b == null) {
|
||||
@@ -1150,7 +1150,7 @@
|
||||
* Checks if `value` is, or can be coerced to, a finite number.
|
||||
*
|
||||
* Note: This is not the same as native `isFinite`, which will return true for
|
||||
* booleans and empty strings. See http://es5.github.com/#x15.1.2.5.
|
||||
* booleans and empty strings. See http://es5.github.io/#x15.1.2.5.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -1223,7 +1223,7 @@
|
||||
*/
|
||||
function isObject(value) {
|
||||
// check if the value is the ECMAScript language type of Object
|
||||
// http://es5.github.com/#x8
|
||||
// http://es5.github.io/#x8
|
||||
// and avoid a V8 bug
|
||||
// http://code.google.com/p/v8/issues/detail?id=2291
|
||||
return !!(value && objectTypes[typeof value]);
|
||||
@@ -1233,7 +1233,7 @@
|
||||
* Checks if `value` is `NaN`.
|
||||
*
|
||||
* Note: This is not the same as native `isNaN`, which will return `true` for
|
||||
* `undefined` and other values. See http://es5.github.com/#x15.1.2.4.
|
||||
* `undefined` and other values. See http://es5.github.io/#x15.1.2.4.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -4010,6 +4010,7 @@
|
||||
* @param {Object} options The options object.
|
||||
* escape - The "escape" delimiter regexp.
|
||||
* evaluate - The "evaluate" delimiter regexp.
|
||||
* imports - An object of properties to import into the compiled template as local variables.
|
||||
* interpolate - The "interpolate" delimiter regexp.
|
||||
* sourceURL - The sourceURL of the template's compiled source.
|
||||
* variable - The data object variable name.
|
||||
@@ -4022,14 +4023,15 @@
|
||||
* compiled({ 'name': 'moe' });
|
||||
* // => 'hello moe'
|
||||
*
|
||||
* var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
|
||||
* _.template(list, { 'people': ['moe', 'larry'] });
|
||||
* // => '<li>moe</li><li>larry</li>'
|
||||
*
|
||||
* // using the "escape" delimiter to escape HTML in data property values
|
||||
* _.template('<b><%- value %></b>', { 'value': '<script>' });
|
||||
* // => '<b><script></b>'
|
||||
*
|
||||
* // using the "evaluate" delimiter to generate HTML
|
||||
* var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
|
||||
* _.template(list, { 'people': ['moe', 'larry'] });
|
||||
* // => '<li>moe</li><li>larry</li>'
|
||||
*
|
||||
* // using the ES6 delimiter as an alternative to the default "interpolate" delimiter
|
||||
* _.template('hello ${ name }', { 'name': 'curly' });
|
||||
* // => 'hello curly'
|
||||
@@ -4038,7 +4040,7 @@
|
||||
* _.template('<% print("hello " + epithet); %>!', { 'epithet': 'stooge' });
|
||||
* // => 'hello stooge!'
|
||||
*
|
||||
* // using custom template delimiters
|
||||
* // using a custom template delimiters
|
||||
* _.templateSettings = {
|
||||
* 'interpolate': /{{([\s\S]+?)}}/g
|
||||
* };
|
||||
@@ -4046,6 +4048,11 @@
|
||||
* _.template('hello {{ name }}!', { 'name': 'mustache' });
|
||||
* // => 'hello mustache!'
|
||||
*
|
||||
* // using the `imports` option to import jQuery
|
||||
* var list = '<% $.each(people, function(name) { %><li><%= name %></li><% }); %>';
|
||||
* _.template(list, { 'people': ['moe', 'larry'] }, { 'imports': { '$': jQuery });
|
||||
* // => '<li>moe</li><li>larry</li>'
|
||||
*
|
||||
* // using the `sourceURL` option to specify a custom sourceURL for the template
|
||||
* var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' });
|
||||
* compiled(data);
|
||||
|
||||
Reference in New Issue
Block a user