-
Promise A與A+規范查看全部
-
只有圖查看全部
-
var buf = new Buffer(8) 分配一段內存空間,放內容超過長度的部分是不會被緩沖的 buf.length 8 緩存區大小 var buf = new Buffer('12345678')查看全部
-
用new方法創建的實例代表了v8引擎分配的一段內存,基本上是一個數組,成員都是整數值 new Buffer("hello 慕課網") 在buffer對象與字符串相互轉換的時候是需要指定編碼格式的,如果沒有指定,默認是按照utf-8的格式進行轉換,new Buffer("hello 慕課網", "base64")查看全部
-
buffer緩沖,在nodejs里處理二進制的數據。為什么要有buffer呢,因為js的字符串是以utf-8的編碼存儲的,處理二進制的能力是很弱的,而網絡層對于不同資源、文件的請求、響應都是用二進制這種方式進行交互的,所以nodejs就有一個接口來創建存放二進制數據的緩存區,并提供一些方法來對緩存區的數據進行進一步的處理。Buffer在nodejs中是可以全局訪問的,不需要require來加載。查看全部
-
<head> <title>Promise animation</title> <style> .ball{ width: 40px; height: 40px; border-radius: 20px; margin-left: 0px; } .ball1{ background: red; } .ball2{ background: yellow; } .ball3{ background: green; } </style> </head>查看全部
-
<body> <div class="ball ball1"></div> <div class="ball ball2"></div> <div class="ball ball3"></div> <script> var ball1 = document.querySelector(".ball1"); var ball2 = document.querySelector(".ball2"); var ball3 = document.querySelector(".ball3"); var animation = function(ball, distance, callback){ setTimeout(function(){ var marginLeft = ball.style.marginLeft.split("px")[0] - 0; if(marginLeft === distance){ callback && callback(); } else { marginLeft > distance ? marginLeft-- : marginLeft++; ball.style.marginLeft = marginLeft; animation(ball, distance, callback) } }, 13) } animation(ball1, 50, function(){ animation(ball2, 150, function(){ animation(ball3, 300, function(){ alert("ok") }) }) }) </script> </body>查看全部
-
stream 讀比寫快 苯方法查看全部
-
啦啦啦查看全部
-
function promiseAnimate(ball,distance){ return new Promise(function(resolve,reject){ function _antimate(){ window.setTimeout(function(){ var marginLeft = parseInt(ball.style.marginLeft,10); if(marginLeft===distance){ return resolve; }else{ if(marginLeft<distance){ marginLeft++; }else if(marginLeft>distance){ marginLeft--; } ball.style.marginLeft=marginLeft+'px'; _antimate(); } },13); }; _antimate(); }); promiseAnimate(ball1, 100) .then(function(){ return promiseAnimate(ball2, 200) }) .then(function(){ return promiseAnimate(ball3, 300) }) .then(function(){ return promiseAnimate(ball3, 150) }) .then(function(){ return promiseAnimate(ball3, 150) }) .then(function(){ return promiseAnimate(ball1, 150) })查看全部
-
劃重點查看全部
-
promise庫查看全部
-
對于JavaScript來說,對Unicode編碼的數據很容易處理的但是對于二進制數據就沒什么處理方法了。但是在一些TCP數據流或者在操作一些文件數據流的時候,字節流的處理方法還是必須的。nodeJS中便出了處理的策略方法~提供了與String類似對等的全局構造函數Buffer(與其說與String對等,還不如說與Array類似但是有些不同方面還是需要注意),全局那么自然就不要每次的require了。Buffer則node中儲存二進制數據的中介者。查看全部
-
"use strict"; const stream = require("stream"); class ReadStream extends stream.Readable{ constructor(){ super(); } _read(){ this.push("I "); this.push("Love "); this.push("You!\n"); this.push(null); } } class WriteStream extends stream.Writable{ constructor(){ super(); // this._cached = Buffer.from(""); } _write(chunk, encode, cb){ console.log(chunk.toString()); cb(); } } class TransformStream extends stream.Transform{ constructor(){ super(); } _transform(chunk, encode, cb){ this.push(chunk); cb(); } _flush(cb){ this.push("I Love You To!"); cb(); } } let readStream = new ReadStream(); let writeStream = new WriteStream(); let transformStream = new TransformStream(); readStream.pipe(transformStream).pipe(writeStream);查看全部
-
cb&&cb() 是指如果cb不為null,即有傳入方法時,執行cb()方法,這里用了&&運算符的短路原則,避免當cb為空時執行了cb()方法而報錯。 學習了!查看全部
舉報
0/150
提交
取消