当前位置: 首页 > news >正文

网站建设找天宇智能个人网站免费注册

网站建设找天宇智能,个人网站免费注册,南安市网站建设,wordpress主题 ghiutdebounce 防抖 延迟 wait 毫秒后调用 func 方法。 提供 cancel 方法取消延迟的函数调用和 flush 方法立即调用。 可以提供一个 options(选项){leading ,trailing} 决定延迟前后如何触发(注:是 先调用后等待 还是 先等待…

debounce 防抖

延迟 wait 毫秒后调用 func 方法。 提供 cancel 方法取消延迟的函数调用和 flush 方法立即调用。 可以提供一个 options(选项){leading ,trailing} 决定延迟前后如何触发(注:是 先调用后等待 还是 先等待后调用)。 func 调用时会传入最后一次提供给 debounced(防抖动)函数的参数。 后续调用的 debounced(防抖动)函数返回是最后一次 func 调用的结果。

_.debounce(func, [wait=0], [options=])
func (Function): 要防抖动的函数。
[wait=0] (number): 需要延迟的毫秒数。
[options=] (Object): 选项对象。
[options.leading = false] (boolean): 指定在延迟开始前调用
[options.maxWait] (number): 设置 func 允许被延迟的最大值。
[options.trailing = true] (boolean): 指定在延迟结束后调用

注意: 如果 leading 和 trailing 选项为 true, 则 func 允许 trailing 方式调用的条件为: 在 wait 期间多次调用防抖方法。
如果 wait 为 0 并且 leading 为 false, func调用将被推迟到下一个点,类似setTimeout为0的超时。

const fn = debounce(async ()=>{},500)
var fn = debounce(()=>{}, 250, { maxWait: 1000 });
// 避免窗口在变动时出现昂贵的计算开销。
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// 当点击时 `sendMail` 随后就被调用。
jQuery(element).on('click', _.debounce(sendMail, 300, {'leading': true,'trailing': false
}));
// 确保 `batchLog` 调用1次之后,1秒内会被触发。
var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
var source = new EventSource('/stream');
jQuery(source).on('message', debounced);
// 取消一个 trailing 的防抖动调用
jQuery(window).on('popstate', debounced.cancel);

throttle

创建一个节流函数,在 wait 秒内最多执行 func 一次的函数。 该函数提供一个 cancel 方法取消延迟的函数调用以及 flush 方法立即调用。 可以提供一个 options 对象决定如何调用 func 方法, options.leading 与|或 options.trailing 决定 wait 前后如何触发。 func 会传入最后一次传入的参数给这个函数。 随后调用的函数返回是最后一次 func 调用的结果。

_.throttle(func, [wait=0], [options=])
func (Function): 要节流的函数。
[wait=0] (number): 需要节流的毫秒。
[options=] (Object): 选项对象。
[options.leading=true] (boolean): 指定调用在节流开始前。
[options.trailing=true] (boolean): 指定调用在节流结束后。

注意: 如果 leading 和 trailing 都设定为 true 则 func 允许 trailing 方式调用的条件为: 在 wait 期间多次调用。
如果 wait 为 0 并且 leading 为 false, func调用将被推迟到下一个点,类似setTimeout为0的超时。

// 避免在滚动时过分的更新定位
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
// 点击后就调用 `renewToken`,但5分钟内超过1次。
var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
jQuery(element).on('click', throttled);
// 取消一个 trailing 的节流调用。
jQuery(window).on('popstate', throttled.cancel);

delay

延时函数

delay(function(text) { console.log(text); // => 一秒后输出 'later'。
}, 1000, 'later');

xor

xor([1, 2], [2, 3], [3, 4]) // [1, 4]
xorBy([{ x: 1 }], [{ x: 2 }, { x: 1, y: 1 }], 'x'); // [ { x: 2 } ]
var objects = [{ x: 1, y: 2 }, { x: 2, y: 1 }];
var others = [{ x: 1, y: 1 }, { x: 1, y: 2 }];
xorWith(objects, others, _.isEqual); // => [{ x: 2, y: 1 }, { x: 1, y: 1 }]

escape

escape('aa, bb, &<>" cc');//aa, bb, &amp;&lt;&gt;&quot; cc

wrap

var p = wrap(escape, function (func, text) {return '<p>' + func(text) + '</p>';
});
p('aa, bb, & cc') // <p>fred%2C%20barney%2C%20%26%20pebbles</p>

at

var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
at(object, ['a[0].b.c', 'a[1]']) // => [ 3, 4 ]

before

const fn = before(3, () => {console.log(11111);
})
fn() // 11111
fn() // 11111
fn() // 没有反应
fn() // 没有反应

after

var fn = after(3, function () {console.log('1111');
});
fn(); //  无反应 
fn(); //  无反应 
fn(); //  1111
fn(); //  1111
fn(); //  1111

chain

chain([{ 'user': 'barney', 'age': 36 },{ 'user': 'fred', 'age': 40 },{ 'user': 'pebbles', 'age': 1 }
]).sortBy('age').map(function (o) {return o.user + ' is ' + o.age;
}).head() // { 'user': 'pebbles', 'age': 1 }

chunk

chunk(['a', 'b', 'c', 'd', 'e'], 2) // [ [ 'a', 'b' ], [ 'c', 'd' ], [ 'e' ] ]

clone

var a = [{ 'a': 1 }, { 'b': 2 }];
var b = clone(a);
b[0] === a[0] // true

cloneDeep

var a = [{ 'a': 1 }, { 'b': 2 }];
var b = cloneDeep(a);
b[0] === a[0] // false

isEmpty

isEmpty(undefined);// => true
isEmpty(null);// => true
isEmpty(true);// => true
isEmpty(1);// => true
isEmpty("zanlan");// => true
isEmpty([]);// => true
isEmpty({});// => true
isEmpty([1, 2, 3]);// => false
isEmpty({ 'a': 1 });// => false

isEqual

isEqual({}, {}) // true

intersection

intersection([2, 1], [4, 2], [1, 2]); // => [2]
intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); // => [2.1]
intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }]
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
intersectionWith(objects, others, isEqual);// => [{ 'x': 1, 'y': 2 }]

uniq

uniq([2, 1, 2]) // => [2, 1]
uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]
uniqWith(objects, isEqual);// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]

union

union([2], [1, 2]) // => [2, 1]
unionBy([2.1], [1.2, 2.3], Math.floor);// => [2.1, 1.2]unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');// => [{ 'x': 1 }, { 'x': 2 }]
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
unionWith(objects, others, isEqual);
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]

difference

difference([1, 2, 3], [1, 3, 4, 5]); // [2]
differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);// => [3.1, 1.3]
differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');// => [{ 'x': 2 }]
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);// => [{ 'x': 2, 'y': 1 }]

flatten

flatten([1, [2, [3, [4]], 5]]);// => [1, 2, [3, [4]], 5]
flattenDeep([1, [2, [3, [4]], 5]]);// => [1, 2, 3, 4, 5]
var array = [1, [2, [3, [4]], 5]];
flattenDepth(array, 1); // => [1, 2, [3, [4]], 5]
flattenDepth(array, 2); // => [1, 2, 3, [4], 5]

isMatch

var object = { a: 1, b: 2, c: 3 };
isMatch(object, { b: 2, c: 3 }) // true
isMatch(object, { b: 1 }) // false

pick

var object = { 'a': 1, 'b': '2', 'c': 3 };
pick(object, ['a', 'c']);// => { 'a': 1, 'c': 3 }
pickBy(object,isNumber); // => { 'a': 1, 'c': 3 }

sortBy

var users = [{ 'user': 'fred',   'age': 48 },{ 'user': 'barney', 'age': 36 },{ 'user': 'fred',   'age': 40 },{ 'user': 'barney', 'age': 34 }
];
sortBy(users, function(o) { return o.user; });
// => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]sortBy(users, ['user', 'age']);
// => [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]sortBy(users, 'user', function(o) {return Math.floor(o.age / 10);
});
// => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

sample

sample([1, 2, 3, 4]); // => 随机得到一项
sampleSize([1, 2, 3], 2);// => [3, 1]
sampleSize([1, 2, 3], 4);// => [2, 3, 1]

shuffle

// 打乱数组
shuffle([1, 2, 3, 4]);// => [4, 1, 3, 2]

groupBy

groupBy([6.1, 4.2, 6.3], Math.floor); // => { '4': [4.2], '6': [6.1, 6.3] }
groupBy(['one', 'two', 'three'], 'length');// => { '3': ['one', 'two'], '5': ['three'] }

uniqueId

uniqueId('contact_');// => 'contact_104'
uniqueId();// => '105'
http://www.dtcms.com/a/401998.html

相关文章:

  • 网站商城建设费用实木餐桌椅移动网站建设
  • 免费的黄金网站有哪些苏州网站建设搜q479185700
  • 怎么在自己的网站做淘宝客随州网站设计开发服务
  • 网站维护中要多久才能重新进入wordpress 搬瓦工迁移
  • 淄博网站建设 百度知道成都地区网站开发成本
  • 万江网站制作亚马逊店铺网站建设费用
  • 建c2c网站厦门网红
  • 成都电商网站开发马鞍山网站建设咨询电
  • 教育网站网址英迈寰球网站建设
  • 网站架构建设wordpress彩色
  • 项目外包网站怎么提高网站访问量
  • 一个网站开发团队中国交通建设集团有限公司地址
  • 深圳网络公司做网站河南郑州房产网
  • 公司网站建设费属于什么费用wordpress免费汉化主题
  • 网站有源代码如何做seo专门做ppt的网站
  • 前端静态网站模板下载中国企业公示信息网官网
  • 微网站建设目的潍坊百度推广优化
  • 网站建设商城制作软件开发具体流程
  • 莱芜网络推广公司提供防城港seo公司
  • 余姚网站制作公司米定制网的网站是那个公司做
  • 怎样做一个好的网站普通展示型网站
  • 古冶区城乡建设局网站傻瓜式建站平台
  • 建一个公司网站需要几天wordpress固定链接文章别名
  • me域名网站国外做兼职网站有哪些
  • 怎么在网站挂黑链接网页设计科技有限公司
  • 顺德网站建设制作深圳哪里有做网站的公司
  • 网站漂浮图片网站注销
  • 系统网站哪个好影视后期行业前景
  • 内蒙古工程建设网站网页的建设流程怎么确定
  • 淘宝网站链接怎么做要郑州网站开发工程师