開発環境
- OS X Lion - Apple(OS)
- Safari (Webプラウザ)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:JavaScript
- JavaScript Library: jQuery
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-87311-425-5) の13章(カスタムオブジェクトと例外の処理)練習問第13-1を解いてみる。
その他参考書籍
13-1.
コード(BBEdit)
Number.prototype.triple = function () { return 3 * this; }; var n = parseFloat($('#t0').val(), 10); $('#pre0').text(n + " * 3 = " + n.triple());
ちなみにPython3kの場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 # -*- coding: utf-8 -*- class MyFloat(float): def triple(self): return 3 * self for x in range(10): i = MyFloat(x) print(i.triple())
入出力結果(Terminal)
$ ./sample.py 0.0 3.0 6.0 9.0 12.0 15.0 18.0 21.0 24.0 27.0 $
0 コメント:
コメントを投稿