Skip to content

Instantly share code, notes, and snippets.

View Yawenina's full-sized avatar
😀

Yawen Xiao Yawenina

😀
View GitHub Profile
@Yawenina
Yawenina / parser.js
Created November 12, 2019 09:49
Generate AST
/**
*if (1 > 0) {
alert('1 > 0');
}
*
* @param {*} params
*/
function parser(tokens) {
let i = -1;
@Yawenina
Yawenina / tokenize.js
Created November 12, 2019 06:23
tokenize js code
function tokenize(code) {
const tokens = [];
const length = code.length;
let char;
for (let i = 0; i < length; i++) {
char = code.charAt(i);
if (/;/.test(char)) {
const token = {
@Yawenina
Yawenina / debounce-throttle-trial.js
Last active July 15, 2017 08:48
simple debounce and throttle
function debounce(fn, wait, leading = false) {
let timerId,
lastInvokeTime = 0,
context,
args;
const execute = function () {
fn.apply(context, args);
lastInvokeTime = Date.now();
};
@Yawenina
Yawenina / debounce-lodash.js
Last active December 27, 2022 03:45
lodash debounce and throttle source code
const nativeMax = Math.max;
const nativeMin = Math.min;
function debounce(func, wait, options) {
let lastArgs,
lastThis,
maxWait,
result,
timerId,
lastCallTime,
lastInvokeTime = 0,