[gist]

from http://oyanglul.us

1 2 3 4 5 6 7 8 9 10 11 12 13 14
         

          var 
          Request 
          = 
          require
          (
          "sdk/request"
          ).
          Request
          ;

         
         

          var 
          request 
          = 
          function
          (
          url
          , 
          method
          , 
          data
          ){

         
             
          var 
          res 
          = 
          $
          .
          Deferred
          ();

         
             
          Request
          ({

         
               
          url
          : 
          url
          ,

         
               
          content
          : 
          data
          ,

         
               
          onComplete
          : 
          function 
          (
          response
          ) 
          {

         
                 
          res
          .
          resovle
          (
          response
          .
          json
          );

         
               
          }

         
             
          })[
          method
          ]();

         
             
          return 
          res
          ;

         
         
          }
         
         
           
         
         

          module
          .
          exports 
          = 
          request

         

view raw
moz-request.js hosted with ❤ by
GitHub

    原文作者:oyanglulu
    原文地址: https://segmentfault.com/a/1190000000638877
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞