Skip to content

Instantly share code, notes, and snippets.

View SoarLin's full-sized avatar
🐢
take it easy

soar_lin SoarLin

🐢
take it easy
View GitHub Profile
@SoarLin
SoarLin / lambda-get-ip.js
Created September 2, 2018 08:01
AWS Lambda Function to Get Internet IP
const http = require('http');
exports.handler = function(event, context, callback) {
const option = {
"hostname": "api.ipify.org",
"path": "/?format=JSON",
"method": "GET"
};
callback(null, Request(option).
@SoarLin
SoarLin / Promise-other-methods.js
Last active July 29, 2022 14:11
Implement Promise
MyPromise.prototype.catch = function(catchFunc) {
return this.then(null, catchFunc)
}
MyPromise.resolve = function(value) {
return new MyPromise((resolve, reject) => {
resolve(value);
})
}
MyPromise.reject = function(value) {
return new MyPromise((resolve, reject) => {
function inherit(Child, Parent) {
// 繼承原型上的屬性
Child.prototype = Object.create(Parent.prototype);
// 修復 constructor
Child.prototype.constructor = Child;
// 儲存超類別
Child.super = Parent;
@SoarLin
SoarLin / debounce.js
Last active November 5, 2022 07:00
throttle and debounce sample and test code
// 適用場景:偵測 input 做搜尋或自動完成
// inputEl.addEventListener('keyup', debounce(func, 500));
function debounce(func, delay = 200) {
let timer = null;
return (...args) => {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
func.apply(this, args);
}, delay);