function ready(fn){
if(document.addEventListener) {
document.addEventListener('DOMContentLoaded', function(){
document.removeEventListener('DOMContentLoaded',arguments.callee,false);
fn();
Promise是异步编程的一种解决方法,相比起传统的回调函数以及事件,有了更好的可读性
Promise有3种状态,分别是pending
、resolved
(准确来说应该叫fulfilled)、rejected
,状态的转换不可逆转,也就是说,一旦状态从pending转变为其他两个状态中的任意一个,那么状态就是固定不变的。
有了promise对象,我们可以通过then
的操作链来传入回调,在一个操作链中,前面的then回调执行完毕之后会将执行结果传递到下一个then,我们就可以将异步编程以同步编程的编程习惯表达(generator和async在这方面可以更彻底)。
promise一旦创建后立即执行,无法中途取消,并且内部抛出的错误无法传递到外部,因此无法在外部捕获
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
{ | |
"schema_version": 1, | |
"name": "微信公众号", | |
"description": "No description provided", | |
"source_url": false, | |
"guid": "c0be876a712baf52fa4270d6b1744432", | |
"tag_fg_color": "#ffffff", | |
"tag_bg_color": "#00b050", | |
"icon": "leaf", | |
"exported_at": "2018-08-31T08:09:17Z", |
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
// 将文件上传到七牛 | |
// from: https://www.ntweet.net/article/59c21ef05d46937dd8491992 | |
//qiniuConfig.js | |
exports.conf = { | |
accessKey: 'xxx', | |
secretKey: 'xxx', | |
bucket: 'xxx' // 要上传的空间 | |
} |
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 Ajax = (function() { | |
var methodsList = ['get', 'post', 'head', 'options', 'put', 'connect', 'trace', 'delete']; | |
/** | |
* Ajax | |
* @param {String} url | |
* @param {Function} callback | |
* @param {Object/String} data | |
* @param {Object} options | |
* |
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 http = require('http') | |
const url = require('url') | |
const path = require('path') | |
const fs = require('fs') | |
const mime = { | |
"html": "text/html", | |
"css": "text/css", | |
"js": "text/javascript", | |
"json": "application/json", | |
"gif": "image/gif", |