タグ

ブックマーク / pig.hatenadiary.com (2)

  • npm q べんり - pig's diary

    qはPromises/A提案ベースの非同期管理ユーティリティです。 https://github.com/kriskowal/q/wiki/API-Reference と思ってたら、今はPromises/A+ というものがあるようです。 http://promises-aplus.github.io/promises-spec/ qがあれば、非同期処理が増えてインデントが増えて読みにくくなったり、クロージャ構造で変数を参照し過ぎてリファクタリングしにくいコードになるのを、ある程度防ぐことができます。 以下は、同期処理と非同期処理を順番に処理していく例です。 var Q = require('q'); var step1 = function(v) { var d = Q.defer(); setTimeout(function() { d.resolve(v); }, 100); retu

    npm q べんり - pig's diary
  • CSS3時代にstylus - pig's diary

    stylus を使ってコードが短くなった例。 iPhone HOME みたいな配置がしたかった(アイテムが出てからリサイズしてみてください) のですが、CSS が長ったらしくなりわけが分からなくなりました。 HUNDRED = 100% itemHeight = 240px /* TODO: Use stylus iterator */ @media only screen and (max-width: 749px) .word:nth-child(1) .word:nth-child(2) top 0 .word:nth-child(3) .word:nth-child(4) top itemHeight .word:nth-child(5) .word:nth-child(6) top itemHeight * 2 .word:nth-child(7) .word:nth-child

    CSS3時代にstylus - pig's diary
  • 1