GolderBrother

Results 52 comments of GolderBrother

```js ~(function(){ Function.prototype.before = function(beforeFn){ return (...args) => { // 先执行传入的beforeFn的函数 beforeFn.apply(this, args); // 再执行调用beforeFn的函数 const res = this.apply(this, args); return res; } } Function.prototype.after = function(afterFn){ return (...args) =>...

```js ```js ~(function(){ Function.prototype.before = function(beforeFn){ return (...args) => { // 先执行传入的beforeFn的函数 beforeFn.apply(this, args); // 再执行调用beforeFn的函数 const res = this.apply(this, args); return res; } } Function.prototype.after = function(afterFn){ return (...args)...

```js // (1)拼接html字符串,然后一次性插入ul中 const oUl = document.getElementById('root'); const aLi = Array.from(oUl.getElementsByTagName('li')); let str = ''; for (let index = aLi.length - 1; index >= 0; index--) { str += `${aLi[index].innerHTML}`;...

* 转换方法 - 使用 Array.from() - 使用 Array.prototype.slice.call() - 使用 Array.prototype.forEach() 进行属性遍历并组成新的数组 * 转换须知 - 转换后的数组长度由 length 属性决定。索引不连续时转换结果是连续的,会自动补位。

class LinkCall { constructor(name) { this.name = name; } call(params) { console.log(params); this.params = params; // 核心点在于最后返回实例本身 return this; } } const linkCall = new LinkCall('james'); linkCall.call('call one').call('call two').call('call three');...

```js function parseMoney(num) { let [interger, decimal ] = String.prototype.split.call(num, '.'); interger = interger.replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,'); decimal = decimal ? `.${decimal}` : ''; return interger + decimal; } console.log(parseMoney(153812.7)); ```

```js function sleep(fn, delay, ...args) { return new Promise((resolve, reject) => { setTimeout(() => { try { const result = typeof fn === 'function' && fn.apply(this, args); resolve(result); } catch...

```js const timeout = (ms) => new Promise((resolve, reject) => { setTimeout(() => { resolve(); }, ms); }); const ajax1 = () => timeout(2000).then(() => { console.log("1"); return 1; });...

```js // 按要求完成代码 const timeout = (ms) => new Promise((resolve, reject) => { setTimeout(() => { resolve(); }, ms); }); const ajax1 = () => timeout(2000).then(() => { console.log("1"); return...

```js ~(function(){ String.prototype.myTrim = function(){ return this.replace(/^\s*|\s*$/g, ''); } })(); console.log(' hello world '.myTrim()); // hello world console.log('abcd '.myTrim()); // abcd ```