自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(220)
  • 收藏
  • 关注

原创 函数防抖debounce方法 / 节流throttle方法

防抖debounce:当持续触发事件时,一定时间段内没有再触发事件,事件处理函数才会执行一次。function debounce(method, context) { clearTimeout(method.tId) method.tId = setTimeout(function() { method.call(context) }, 100)}function...

2019-09-02 20:47:03 511

原创 防篡改对象(不可扩展对象、密封对象、冻结对象)

不可扩展对象:不能添加var person = {name: 'wangdanting'};Object.preventExtensions(person);person.age = 23;console.log(person.age); // => undefinedperson.name = 'abc';console.log(person.name); // =&g...

2019-09-02 17:47:23 251

原创 基本的函数柯里化curry方法

function curry(fn) { var args = Array.prototype.slice.call(arguments, 1) return function() { var innerArgs = Array.prototype.slice.call(arguments) var finalArgs = args.concat(innerArgs) ...

2019-09-02 17:34:11 374

原创 基本的函数绑定bind方法

function bind(fn, context) { return function() { return fn.apply(context, arguments) }}var greet = function(greeting, punctuation) { return greeting + " " + this.user + punctuation}var...

2019-09-02 17:32:15 547

原创 创建一个函数,调用func时,this绑定到创建的新函数,并且start之后的参数作为数组传入

/** * 创建一个函数,调用func时,this绑定到创建的新函数,并且start之后的参数作为数组传入 * Creates a function that invokes `func` with the `this` binding of the * created function and arguments from `start` and beyond provided as a...

2019-08-24 18:53:50 495

原创 检查value是否是一个原生函数

/** * 检查value是否是一个原生函数 * Checks if `value` is a pristine native function * @param {*} value The value to check * @returns {boolean} Returns `true` if `value` is a native function, else `false` *...

2019-08-23 15:48:47 165

原创 创建一个调用函数,使调用次数不操过n次,之后再调用这个函数,将返回一次最后调用func的结果

/** * 创建一个调用函数,通过this绑定和创建函数的参数调用func,调用次数不操过n次,之后再调用这个函数, * 将返回一次最后调用func的结果 * Creates a function that invokes `func`, with the `this` binding and arguments * of the created function, while it's...

2019-08-21 11:58:47 464

原创 计算数组的平均值

/** * 计算array的平均值 * Computes the mean of the values in `array` * @param {Array} array The array to iterate over * @returns {number} Returns the mean * @example * mean([4, 2, 8, 6]) * // => ...

2019-08-20 16:40:21 802

原创 计算数组中的最大值,如果数组是空的或者是非数组则返回undefined

/** * 计算array中的最大值,如果array是空的或者是非数组则返回undefined * computes the maximum value of `array`. If `array` is empty or falsey * `undefined` is returned. * @param {Array} array The array to iterate over...

2019-08-20 15:46:28 362

原创 根据precision(精度)向上舍入number

/** * 根据precision(精度)向上舍入number。(precision(精度)可以理解为保留几位小数) * Computes `number` rounded up to `precision` * @param {number} number The number to round up * @param {number} [precision=0] The precis...

2019-08-19 17:34:14 467

原创 两个数相加

/** * Adds two numbers * 两个数相加 * @param {number} augend The first number in an addition * @param {number} addend The second number in an addition * @returns {number} Returns the total * @exampl...

2019-08-19 15:11:44 350

原创 产生一个包括lower与upper之间的数

/** * 产生一个包括lower与upper之间的数,如果只提供一个参数返回一个0到提供数之间的数, * 如果floating设为true,或者lower或upper是浮点数,结果返回浮点数 * @param {number} [lower=0] The lower bound * @param {number} [upper=1] The upper bound * @param ...

2019-08-19 10:37:29 351

原创 检查数值是否在start与end之间,但不包括end

/** * 检查n是否在start与end之间,但不包括end。如果end没有指定,那么start设置为0, * 如果start大于end,那么参数会交换以便支持负范围。 * Checks if `n` is between `start` and up to, but not including, `end`. * If `end` is not specified, it's set...

2019-08-08 22:22:28 423

转载 重复N次给定字符串

/** * 重复N次给定字符串 * Repeats the given string `n` times * @param {string} [string=''] The string to repeat * @param {number} [n=1] The number of times to repeat the string * @returns {string} Retur...

2019-08-06 11:18:16 1125

转载 转义字符串中的'&', '<', '>', '"', "'", "`" 字符为HTML实体字符

/** * 转义字符串中的'&', '<', '>', '"', "'", "`" 字符为HTML实体字符 * **注意:** 不会转义其他字符 * Converts the characters '&', '<', '>', '"', "'", "`" in `string` to their corresponding HTML entities...

2019-08-06 11:17:44 887

转载 替换字符串中匹配的字符为给定的替代字符

/** * 替换string字符串中匹配的pattern为给定的replacement * Replaces matches for `pattern` in `string` with `replacement` * @param {string} [string=''] The string to modify * @param {RegExp|string} pattern The...

2019-08-06 11:16:37 479

原创 如果字符串长度小于length则从左侧和右侧填充字符,如果没法平均分配,则截断超出的长度

/** * 如果string字符串长度小于length则从左侧和右侧填充字符,如果没法平均分配,则截断超出的长度 * Pads `string` on the left and right sides if it's shorter than `length`. * Padding characters are truncated if they can't be evenly divid...

2019-08-05 22:59:30 339

原创 转换字符串以空格分开单词,并转为小写

/** * 转换字符串以空格分开单词,并转为小写 * Converts `string`, as space separated words, to lower case * @param {string} [string=''] The string to convert * @returns {string} Returns the lower cased string * @ex...

2019-08-04 23:53:50 390

原创 转换字符串为中滑线连接格式

/** * 转换字符串为中滑线连接格式 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) * @param {string} [string=''] The string to convert * @returns {string} Retu...

2019-08-04 00:02:28 202

原创 转义RegExp字符串中特殊的字符"^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", "|"

/** * 转义RegExp字符串中特殊的字符"^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", "|" * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", * "?", "(", ")", "[", "]", "{", ...

2019-08-03 22:02:03 7500

原创 检查字符串是否以给定的字符串结尾

/** * 检查字符串string是否以给定的target字符串结尾 * Checks if `string` ends with the given target string * @param {string} [string=''] The string to inspect * @param {string} [target] The string to search for ...

2019-08-02 17:32:03 461

原创 转换字符串string为驼峰写法

/** * 转换字符串string为驼峰写法 * Converts `string` to [camel case] * @param {string} [string=''] The string to convert * @returns {string} Returns the camel cased string * @example * camelCase('Foo Bar...

2019-08-02 16:15:59 1526

原创 拆分字符串string中的词变为数组

/** * 拆分字符串string中的词为数组 * Splits `string` into an array of its words * @param {string} [string=''] The string to inspect * @param {RegExp|string} [pattern] The pattern to match words * @returns ...

2019-08-02 12:30:47 263

原创 转换字符串string中拉丁语-1补充字母和拉丁语扩张字母-A为基本的拉丁字母,并且去除组合变音标记

/** * 转换字符串string中拉丁语-1补充字母和拉丁语扩张字母-A为基本的拉丁字母,并且去除组合变音标记 * Deburrs `string` by converting * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) ...

2019-08-01 17:22:12 1137

原创 转换字符串string的首字母为大写(或小写)

/** * 转换字符串string的首字母为大写 * Converts the first character of `string` to upper case * * @param {string} [string=''] The string to convert * @returns {string} Returns the converted string * @examp...

2019-08-01 11:54:24 2485

原创 创建一个去重后的数组副本

/** * 创建一个去重后的array数组副本,使用了全等比较,只有第一次出现的元素才会被保留 * Creates a duplicate-free version of an array, in which only the first occurrence of each element * is kept. The order of result values is determin...

2019-07-31 15:15:05 197

原创 这个方法类似indexOf,除了它是在已经排序的数组array上执行二进制检索

/** * 这个方法类似indexOf,除了它是在已经排序的数组array上执行二进制检索 * This method is like `indexOf` except that it performs a binary search on a sorted `array` * @param {Array} array The array to inspect * @param {*} ...

2019-07-30 16:16:01 544

原创 使用二进制的方式检索来决定value值应该插入到数组中尽可能小的索引位置,以保证数组的排序

/** * 使用二进制的方式检索来决定value值应该插入到数组中尽可能小的索引位置,以保证数组的排序 * Uses a binary search to determine the lowest index at which `value` should be inserted * into `array` in order to maintain its sort order. * ...

2019-07-30 15:06:01 232

原创 反转array, 使得第一个元素变为最后一个元素,第二个元素变为倒数第二个元素,以此类推

/** * 反转array, 使得第一个元素变为最后一个元素,第二个元素变为倒数第二个元素,以此类推 * **注意:**:这个方法会改变原数组array * Reverses `array` so that the first element becomes the last, the second element becomes * this second to last, and s...

2019-07-29 15:06:19 1222

原创 获取数组的第n个元素,如果n为负数,则返回从数组结尾开始的第n个元素

/** * 获取array数组的第n个元素,如果n为负数,则返回从数组结尾开始的第n个元素 * Gets the element at index `n` of `array`, if `n` is negative, the nth * element from the end is returned * @param {Array} array The array to query...

2019-07-29 11:33:54 540

原创 获取数组中的最后一个元素

/** * 获取array中的最后一个元素 * Gets the last element of `array` * @param {Array} array The array to query * @returns {*} Returns the last element of `array` * @example * last([1, 2, 3]) * // => 3...

2019-07-27 17:36:53 13065

原创 将数组中所有的元素转换为由分隔符分隔的字符串

/** * 将array中所有的元素转换为由separator分隔的字符串 * Converts all elements in `array` into a string separated by `separator` * * @param {Array} array The array to convert * @param {string} [separator=','] Th...

2019-07-27 17:36:13 1055

原创 获取数组array中除了最后一个的所有元素(去除数组array中的最后一个元素, 返回新数组)

/** * 获取数组array中除了最后一个的所有元素(去除数组array中的最后一个元素, 返回新数组) * Gets all but the last element of `array` * @param {Array} array The array to query * @returns {Array} Returns the slice of `array` * @exam...

2019-07-26 18:05:04 3532

原创 返回一个由键值对pairs构成的对象

/** * 与toPairs正好相反,这个方法返回一个由键值对pairs构成的对象 * The inverse of `_.toPairs`; this method returns an object composed from key-value `pairs`. * @param {Array} pairs The key-value pairs * @returns {Objec...

2019-07-26 17:24:34 272

原创 根据depth递归减少array的嵌套层级

/** * 根据depth递归减少array的嵌套层级 * Recursively flatten `array` up to `depth` times. * @param {Array} The array to flatten * @param {number} [depth=1] The maximum recursion depth. * @returns {Array} R...

2019-07-26 16:54:33 283

原创 将array递归为一维数组

/** * 将array递归为一维数组 * @param {Array} array The array to flattens * @returns {Array} Returns the new flattened array * @example * flattenDeep([1, [2, [3, [4]], 5]]) * // => [1, 2, 3, 4, 5] *...

2019-07-26 15:50:33 237

原创 获取数组array的第一个元素

/** * 获取数组array的第一个元素 * Gets the first element of `array` * * @param {Array} array The array to query * @returns {*} Returns the first element of `array` * @example * head([1, 2, 3]) * // =&g...

2019-07-26 11:04:33 8459

原创 使用value值来填充(替换)array, 从start位置开始,到end位置结束(但不包含end位置)

/** * 使用value值来填充(替换)array, 从start位置开始,到end位置结束(但不包含end位置)。 * 这个方法会改变array(不是创建新数组) * Fills elements of `array` with `value` from `start` up to, but not including `end` * **Note:** This method mu...

2019-07-26 10:43:10 268

原创 创建一个切片数组,去除array前面的n个元素(n默认值为1)

/** * 创建一个切片数组,去除array前面的n个元素(n默认值为1) * Creates a slice of `array` with `n` elements dropped from the beginning * @param {Array} array The array to query * @param {number} [n=1] The number of ele...

2019-07-25 10:12:19 498

原创 使用等值比较,返回首次value在数组array中被找到的索引值

/** * Gets the index at which the first occurrence of `value` is found in `array` using [`SameValueZero`] * for equality comparisons. If `fromIndex` is negative, it's used as the offset from the en...

2019-07-24 15:51:21 227

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除