開発環境
- OS X Lion - Apple(OS)
- Safari、Firefox + Firebug (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.を解いてみる。
その他参考書籍
1.
コード(BBEdit)
Number.prototype.triple = function ( ) { return 3 * this; }; var result = (10).triple() + "\n" + (1.5).triple(); $('#pre0').text(result);
ちなみにPython3kの場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 # -*- coding: utf-8 -*- class MyNum(float): def triple(self): return 3 * self a = MyNum(10) b = MyNum (1.5) print(a.triple(), b.triple())
入出力結果(Terminal)
$ ./sample.py 30.0 4.5 $
0 コメント:
コメントを投稿