zoukankan      html  css  js  c++  java
  • callback转Promise

    环境:  nodejs - v6.2.0

     1 const fs = require('fs');
     2 
     3 let Promise = require('bluebird');
     4 
     5 let readSync = function(filePath) {
     6   return new Promise(function(resolve, reject) {
     7       fs.unlink(filePath, (err) => {
     8         if(err) return reject(err);
     9         return resolve();
    10       })
    11   })
    12 }
    13 
    14 readSync('log').then(function(data) {
    15   console.log('OKKKKK');
    16 }).catch(function(err) {
    17   console.log(err || 'errror!!');
    18 })

  • 相关阅读:
    window
    pages
    百度小程序 配置 app.json 文件
    JavaScript Cookie
    jQuery ajax
    jQuery ajax
    jQuery ajax
    jQuery
    jQuery
    jQuery
  • 原文地址:https://www.cnblogs.com/maduar/p/6091685.html
Copyright © 2011-2022 走看看