開発環境
- OS X Mavericks - Apple (OS)
- Dart Editor (開発環境)
- Dart (プログラミング言語)
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリージャパン、2009年、ISBN978-4-87311-425-5) の4章(オブジェクト)、練習問第4-1, 4-2, 4-3, 4-4, 4-5.をDartで解いてみる。
その他参考書籍
- What is Dart? [Kindle版] (O'Reilly Media) Kathy Walrath Seth Ladd (著) このブログでの感想
練習問第4-1, 4-2, 4-3, 4-4, 4-5.
コード
sample.dart
import 'dart:html'; void main(){ var run = querySelector('#run'), clear = querySelector('#clear'), pre0 = querySelector('#pre0'), t0 = querySelector('#t0'); run.onClick.listen((MouseEvent event){ var result = window.navigator.userAgent + '\n'; String comma_separated_str = t0.value; var list = comma_separated_str.split(','), reversed_list = list.reversed, str = 'The fun of functions is that they are functional.', pattern = new RegExp(r'\bfun\b'), replaced_str = str.replaceAll(pattern, 'power'), today = new DateTime.now(), td = today.day, d_week_ago = today.add(new Duration(days:7)).day, n = 34.44, m = n.floor(), l = n.ceil(), i; result += '1.\n'; result += '3番目の要素; ${list[2]}\n'; result += '逆順: ${reversed_list}\n'; result += '2.\n'; result += '置換前: ${str}\n'; result += '置換後: ${replaced_str}\n'; result += '3.\n'; result += '今日の日付: ${td}日\n'; result += '1週間後の日付: ${d_week_ago}日\n'; result += '4.\n'; result += '数値: ${n}\n'; result += '切り下げ: ${m}\n'; result += '切り上げ: ${l}\n'; result += '5.\n'; str = 'apple.orange-strawberry,lemon-.lime'; replaced_str = str.replaceAll(new RegExp(r'[,.]'), ','); list = replaced_str.split(','); for(i = 0; i < list.length; i += 1){ result += '$i: ${list[i]}\n'; } pre0.text = result; }); clear.onClick.listen((MouseEvent event) => pre0.text = ''); }1.
0 コメント:
コメントを投稿