0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

javascriptメモ2

Last updated at Posted at 2020-05-19

Node.jsのステップ実行

VSCで出来る。
VS201xでも昔試した記憶あるけど何も覚えていない。。

Promise

      var btn_promise = cube.getButtonStatus()
      btn_promise.then((value) => {
          console.log(value);  // 1
          //cube.playPresetSound( 4);
            //console.log("btn = " , String(btn))
      }, (error) => {
        console.error("error:", error.message);
      });

sleep

侍エンジニア塾の最初のロゴ、すごい邪魔なんですけど(怒)

// ビジーwaitを使う方法
function sleep2(waitMsec) {
  var startMsec = new Date();

  // 指定ミリ秒間だけループさせる(CPUは常にビジー状態)
  while (new Date() - startMsec < waitMsec);
}

function sleep(waitSec, callbackFunc) {
    // 経過時間(秒)
    var spanedSec = 0;
    // 1秒間隔で無名関数を実行
    var id = setInterval(function () {
        spanedSec++;
        // 経過時間 >= 待機時間の場合、待機終了。
        if (spanedSec >= waitSec) {
            // タイマー停止
            clearInterval(id);
            // 完了時、コールバック関数を実行
            if (callbackFunc) callbackFunc();
        }
    }, 1000);
}

enum

JavaScriptにはない、TypeScriptにはある。

enum Color {
    Red,
    Green,
    Blue
}
var col = Color.Red;
col = 0; // Effectively same as Color.Red

 format

function test()
{
var str = "もじれつ";
var num = 555;
var flo = 1.7320508075;

console.log('Stringの出力 : %s', str);
console.log('Numberの出力 : %d', num);
console.log('Floatの出力  : %f', flo);

console.log('複数出力 : %s %d %f',str,num,flo);

}

メモ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?