This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x = 2; | |
Number.prototype.valueOf = function () { | |
return x++; | |
}; | |
const a = new Number(2); | |
console.log(a == 2 && a == 3 && a == 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1, 2, 3, 'x', 'f', 'y']; | |
// for (const i of arr) { | |
// console.log(i); | |
// } | |
const it = arr[Symbol.iterator](); | |
for (let res; (res = it.next()) && !res.done; ) { | |
console.log(res.value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isWeChat = () => /MicroMessenger/i.test(window.navigator.userAgent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [ | |
{ name: 'zs', age: 15, happy: ['唱歌', '玩游戏'] }, | |
{ name: 'ls', age: 15, happy: ['玩游戏'] }, | |
{ name: 'zs', age: 15, happy: ['学习', '划水'] }, | |
]; | |
function test(arr) { | |
let _obj = {}; | |
let _arr = []; | |
if (!arr.length) return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "typescript": "~4.1.5" | |
type Debounce = { | |
<T extends unknown[]>(fn: (...arg: T) => void | unknown, ms: number): ( | |
this: unknown, | |
...arg: T | |
) => void | unknown; | |
}; | |
/** | |
* debounce function wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ParentA { | |
constructor() { | |
this.id = 'a'; | |
} | |
foo() { | |
console.log('Parent A: ', this.id); | |
} | |
} | |
class ParentB { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* fibonacciSquence() { | |
let x = 0, | |
y = 1; | |
for (;;) { | |
yield y; | |
[x, y] = [y, x + y]; | |
} | |
} | |
const fibonacci = (n: number) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fibonacci(num) { | |
let count = 0; | |
let result = [1, 1]; | |
if (num <= 1) { | |
return result; | |
} | |
let n = num - 2; | |
for (let i = 0; i < n; i++) { | |
result.push(result[count] + result[count + 1]); | |
count++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xfy = (() => { | |
let name = 'xfy'; | |
let age = 18; | |
let obj = {}; | |
Object.defineProperty(obj, 'test', { | |
get: function () { | |
return name + ' : ' + age; | |
}, | |
set: function (value) { | |
name = value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = { | |
a: "xfy", | |
b: { | |
c: "test", | |
}, | |
d: 123, | |
e: [1, 2, 3, 4, 5], | |
f: { | |
g: 'array', | |
h: [1, 2, 3, 4, 5, 6, { |
OlderNewer