This file contains hidden or 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 action = { | |
succ_get_name : res=>console.log('dispatch: SUCC_GET_MAME',res), | |
fail_get_name : res=>console.log('dispatch: FAIL_GET_MAME',res), | |
succ_get_book : res=>console.log('dispatch: SUCC_GET_BOOK',res), | |
fail_get_book : res=>console.log('dispatch: FAIL_GET_BOOK',res), | |
} | |
function api(param,result=true) { | |
console.log('call api: ', param) | |
return {body:'im response', result} |
This file contains hidden or 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
node ./hk11.js "narto" |
This file contains hidden or 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 fs = require('fs') | |
let dir_path = __dirname + '/storage' | |
let file_path = dir_path + '/hello.txt' | |
let str = 'Hello world' | |
if (!fs.existsSync(dir_path)) | |
fs.mkdirSync(dir_path) | |
if (fs.existsSync(file_path)) |
This file contains hidden or 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 proc_strng = require('./proc-string') | |
console.log(proc_strng.string_to_array('Hello world')) | |
console.log(proc_strng.string_to_int('00007777777')) |
This file contains hidden or 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 request = require('request'); | |
request('http://www.google.com', function (error, response, body) { | |
console.log('error:', error); // Print the error if one occurred | |
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received | |
console.log('body:', body); // Print the HTML for the Google homepage. | |
}) |
This file contains hidden or 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
async function map(arr, func) { | |
for (let i = 0; i < arr.length; i++) | |
arr[i] = await func(arr[i]) | |
return arr | |
} | |
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
; (async () => { | |
let arr = [1, 2, 3, 4] |
This file contains hidden or 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 delay(ms) { | |
return new Promise(resolve => setTimeout(() => { | |
console.log(new Date()) | |
resolve() | |
}, ms)) | |
} | |
let p = delay(1000); | |
for (let i = 0; i < 4; i++) { |
This file contains hidden or 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 width = 200; | |
function delayPrintWidth(ms) { | |
let w = width | |
setTimeout(() => console.log(w), ms) | |
} | |
delayPrintWidth(1000); // 預期印 200 | |
width = 300; | |
delayPrintWidth(2000); // 預期印 300 |
This file contains hidden or 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 connect(func1, func2) { | |
let data = { ...func1(), ...func2() } | |
return function (element) { | |
element(data)() | |
} | |
} | |
connect( | |
function () { |
This file contains hidden or 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 map(arr,fun){ | |
for(let i=0;i<arr.length;i++) | |
arr[i] = fun(arr[i]) | |
return arr; | |
} | |
const arr = [1,2,3,4,5] | |
const new_arr = map(arr,function(n){ | |
return n*100 |