codecamp

Lodash _.partial

_.partial(func, [partials])

创建一个函数。 该函数调用 func,并传入预设的 partials 参数。 这个方法类似_.bind,除了它不会绑定 this。这个 _.partial.placeholder 的值,默认是以 _ 作为附加部分参数的占位符。注意: 这个方法不会设置 "length" 到函数上。

添加版本

0.2.0

参数

  1. func (Function): 需要预设的函数
  2. [partials] (...*): 预设的参数

返回

(Function): 返回预设参数的函数。

例子

var greet = function(greeting, name) {  return greeting + ' ' + name;}; 
var sayHelloTo = _.partial(greet, 'hello');sayHelloTo('fred');
// => 'hello fred' // 使用了占位符。
var greetFred = _.partial(greet, _, 'fred');greetFred('hi');
// => 'hi fred'


Lodash _.overArgs
Lodash _.partialRight
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }