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
// Import stylesheets | |
import './style.css'; | |
// Write Javascript code! | |
const appDiv = document.getElementById('app'); | |
appDiv.innerHTML = `<h1>Linked list traversal</h1>`; | |
function log(value) { | |
const span = document.createElement('span'); | |
span.textContent = 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
class LinkedListNode { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
const head = Symbol("linked list's head"); | |
class LinkedList { |
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 queryAllSelectedAPI() { | |
const selectedList = document.querySelectorAll('.list-bd .list-group-wrap .list-row.js-selected'); | |
return Array.from({ length: selectedList.length }).map((_, index) => { | |
const node = selectedList[index] | |
const title = node.querySelector('div.list-col.col-name > a').innerText | |
const link = node.querySelector('div.list-col.col-name > a').getAttribute('href') | |
const name = node.querySelector('div.list-col.col-creator-realname').innerText | |
return `${index+1}、 ${title}(${name}): ${location.origin}${link}` | |
}).join('\n') |
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
var type = "window"; | |
const obj = { | |
type: "obj", | |
foo(a, b) { | |
console.log("this.type", this.type, a, b); | |
} | |
}; | |
Function.prototype.customCall = function (context, ...restArgs) { |
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
Array.prototype.customReduce = function (fn, initialValue) { | |
for (let i = 0; i < this.length; i++) { | |
// 当未传初始值时取数组中的第一项作为初始值 | |
if (typeof initialValue === "undefined") { | |
initialValue = fn(this[i], this[i + 1], i, this); | |
i++; | |
} else { | |
initialValue = fn(initialValue, this[i], i, this); | |
} | |
} |
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 compose = (...fns) => (input) => fns.reverse().reduce((acc, fn) => fn(acc), input); | |
const addOne = (x) => x + 1; | |
const square = (x) => x * x; | |
console.log(compose(addOne, square)(2)); |
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 pipe = (...fns) => (input) => fns.reduce((acc, fn) => fn(acc), input); | |
const addOne = (x) => x + 1; | |
const square = (x) => x * x; | |
console.log(pipe(addOne, square)(2)); |
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
// 定义 | |
export interface MyInputHandles { | |
focus(): void; | |
} | |
const MyInput: RefForwardingComponent<MyInputHandles, MyInputProps> = ( | |
props, | |
ref | |
) => { | |
const inputRef = useRef<HTMLInputElement>(null); |
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
type PromiseType<T> = (args: any[]) => Promise<T>; | |
type UnPromisify<T> = T extends PromiseType<infer U> ? U : never; | |
// 或者这样一句话: type UnPromisify<T> = T extends (args: any[]) => Promise<infer U> ? U : never; | |
// 测试 UnPromisify<T>: | |
async function stringPromise() { | |
return "string promise"; | |
} | |
async function numberPromise() { |
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 overrideSetTimeout(fn) { | |
let timerIds = []; | |
function realSetTimeout(callback, delay) { | |
const args = Array.prototype.slice.call(arguments, 2) | |
const timerId = fn(() => { | |
callback.apply(null, args) | |
}, delay) | |
timerIds.push(timerId); |
NewerOlder