履歴: プログラミング/CoffeeScript
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 18 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2016/4/8 18:12:11 | プログラミング/CoffeeScript 最新版 | 30,938 | +1 | -22 | 表示 | 差分 | — |
| 2016/4/8 18:12:11 | プログラミング/CoffeeScript | 31,782 | +1 | -1 | 表示 | 差分 | 選択 |
| 2016/4/8 9:12:11 | プログラミング/CoffeeScript | 31,761 | +10 | -4 | 表示 | 表示中 | 選択 |
| 2016/3/9 4:20:09 | プログラミング/CoffeeScript | 31,740 | +8 | -1 | 表示 | 差分 | 選択 |
| 2014/5/29 16:05:27 | プログラミング/CoffeeScript | 31,570 | +62 | -15 | 表示 | 差分 | 選択 |
| 2014/5/29 9:52:19 | プログラミング/CoffeeScript | 29,354 | +150 | -27 | 表示 | 差分 | 基準 |
| 2014/5/28 15:58:53 | プログラミング/CoffeeScript | 24,913 | +191 | -2 | 表示 | 差分 | 選択 |
| 2013/11/27 15:06:40 | プログラミング/CoffeeScript | 18,653 | +3 | -0 | 表示 | 差分 | 選択 |
| 2013/11/23 13:44:28 | プログラミング/CoffeeScript | 18,096 | +18 | -0 | 表示 | 差分 | 選択 |
| 2013/5/9 5:34:07 | プログラミング/CoffeeScript | 17,815 | +1 | -1 | 表示 | 差分 | 選択 |
| 2013/5/9 5:34:07 | プログラミング/CoffeeScript | 17,809 | +6 | -5 | 表示 | 差分 | 選択 |
| 2013/5/9 5:34:07 | プログラミング/CoffeeScript | 17,746 | +8 | -0 | 表示 | 差分 | 選択 |
| 2013/5/2 10:58:05 | プログラミング/CoffeeScript | 17,595 | +44 | -0 | 表示 | 差分 | 選択 |
| 2013/4/18 17:07:42 | プログラミング/CoffeeScript | 16,718 | +17 | -17 | 表示 | 差分 | 選択 |
| 2013/4/18 17:07:42 | プログラミング/CoffeeScript | 16,697 | +56 | -5 | 表示 | 差分 | 選択 |
| 2013/4/17 19:06:55 | プログラミング/CoffeeScript | 15,816 | +7 | -3 | 表示 | 差分 | 選択 |
| 2013/4/17 18:54:18 | プログラミング/CoffeeScript | 15,740 | +381 | -1 | 表示 | 差分 | 選択 |
| 2013/4/17 12:53:40 | プログラミング/CoffeeScript | 626 | — | — | 表示 | — | 選択 |
基準: プログラミング/CoffeeScript (2014/5/29 9:52:19) → 比較: プログラミング/CoffeeScript (2016/4/8 9:12:11)
@@ -113,7 +113,7 @@
まあ、車輪の再発明っぽいところもあるわけですが、
祝日名が取れて、なおかつメンテナンスしやすい形の
-ライブラリが見付からなかったので。
+ライブラリが見付からなかったので書いてみました。
一応、https://gist.github.com/Songmu/703311 と突き合わせて
齟齬がないことを確認しましたが、運用は個々の責任でお願いします。
@@ -121,8 +121,20 @@
法律改正などで休日が変更になっても、よほどのことがない限り definition
のところをいじるだけで対応できるはず???
+*** 最新版はこちらです [#j372e199]
+
+現在はこちらで公開しています。
+
+[[ソフトウェア/javascript/japanese-holidays]]
+
*** ソース [#yac07e9e]
+COLOR(red){SIZE(40){''以下のコードは古いです''}}
+
+最新版はこちらで公開しています。
+
+[[ソフトウェア/javascript/japanese-holidays]]
+
LANG:coffeescript(linenumber)
###
@@ -534,16 +546,21 @@
obj.is_a(type) と書けるようにすればタイプ量が少なくて一見良さそうなのですが、
null や undefined に対して呼べなくなってしまうため、
javascript から使うには使いにくくなってしまいます。
-そこで、javascript 用には Object.is_a(obj, type) という仕様の関数を用意してやります。
+そこで、javascript 用には Object.is_a(obj, type) という仕様の関数を用意しました。
一方 Coffee Script では ? を挟んで obj?.is_a(type) と呼べば null や undefined にも対応できるので、
-Object::is_a(type) も便利に使えます。
+Object::is_a(type) も便利に使えます。さらに、obj.is_a(type) 形式で呼び出す場合には、
+is_a の呼び出し時に数値や文字列などのネイティブオブジェクトが Object にカプセル化されるため、
+is_a 関数内でもう一度カプセル化してやる必要はないようです。
+ただ、異なるフレームで作成されたオブジェクトに対してこの関数を呼んでも正しく判定できないようです。~
+参照:http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
+
*** ソース [#hbe8e397]
LANG:coffeescript
Object::is_a = (type)->
- Object(this) instanceof type
+ this instanceof type
Object.is_a = (obj, type)->
obj? and Object(obj) instanceof type
@@ -572,6 +589,7 @@
it "distinguishes Boolean", ->
expect( Object.is_a(true, Boolean) ).toBe true
expect( Object.is_a(true, Object) ).toBe true
+ expect( Object.is_a(1==1, Boolean) ).toBe true
expect( Object.is_a(new Boolean(true), Boolean) ).toBe true
it "distinguishes Array", ->
@@ -633,18 +651,31 @@
describe "Object::is_a", ->
it "works with undefined", ->
- expect( obj?.is_a(Object) ).toBeFalsy()
+ expect( undefined?.is_a(Object) ).toBeFalsy()
+ expect( undefined_obj?.is_a(Object) ).toBeFalsy()
+ `var uninitialized_obj`
+ expect( uninitialized_obj?.is_a(Object) ).toBeFalsy()
it "works with null", ->
- obj = null
- expect( obj?.is_a(Object) ).toBeFalsy()
+ expect( null?.is_a(Object) ).toBeFalsy()
it "works with literal objects", ->
- expect( 0?.is_a(Number) ).toBeTruthy()
- expect( /a/?.is_a(RegExp) ).toBeTruthy()
- expect( false?.is_a(Boolean) ).toBeTruthy()
- expect( []?.is_a(Array) ).toBeTruthy()
- expect( {}?.is_a(Object) ).toBeTruthy()
+ expect( 0 instanceof Number ).toBeFalsy()
+ expect( NaN instanceof Number ).toBeFalsy()
+ expect( 0?.is_a(Number) ).toBeTruthy()
+ expect( NaN?.is_a(Number) ).toBeTruthy()
+ expect( "a" instanceof String ).toBeFalsy()
+ expect( "a"?.is_a(String) ).toBeTruthy()
+ expect( /a/ instanceof RegExp ).toBeTruthy()
+ expect( /a/?.is_a(RegExp) ).toBeTruthy()
+ expect( false instanceof Boolean ).toBeFalsy()
+ expect( (0==0) instanceof Boolean).toBeFalsy()
+ expect( false?.is_a(Boolean) ).toBeTruthy()
+ expect( (0==0)?.is_a(Boolean) ).toBeTruthy()
+ expect( [] instanceof Array ).toBeTruthy()
+ expect( []?.is_a(Array) ).toBeTruthy()
+ expect( {} instanceof Object ).toBeTruthy()
+ expect( {}?.is_a(Object) ).toBeTruthy()
it "works with the super class", ->
class A
@@ -674,6 +705,13 @@
http://webreflection.blogspot.jp/2007/01/javascript-getclass-and-isa-functions.html
のコードはたぶん意図と異なるコードになっているので、気持ちを汲み取って書き直してみました。
+http://api.jquery.com/jQuery.type/ ~
+http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
+
+このあたりを見ると Function.prototype.toString() は実装依存なため下記コードは
+必ずしもすべてのブラウザで動かない可能性もあるのですが、とりあえず試した範囲では大丈夫そう、
+という感じです。
+
*** ソース [#rabfc8d7]
LANG:coffeescript
@@ -682,7 +720,7 @@
Object.class_name_of = (obj)->
return "null" if obj == null
return "undefined" if obj == undefined
- if obj.constructor.toString().match /function\s+(\S+)\(/
+ if obj.constructor.toString().match /function\s+(\S+)\s*\(/
return RegExp.$1
if obj.constructor.prototype?
# search constructor in the global scope
@@ -704,7 +742,7 @@
ではなく、
LANG:javascript
- MyClass = function(){}; # グローバルに宣言された変数
+ MyClass = function(){}; // グローバルに宣言された変数
obj = new MyClass();
alert(Object.class_name_of(obj));
@@ -720,7 +758,7 @@
そもそも上のように頑張ったところで、
LANG:javascript
- var MyClass = function(){}; # ローカルに宣言された変数
+ var MyClass = function(){}; // ローカルに宣言された変数
obj = new MyClass();
alert(Object.class_name_of(obj));
@@ -767,7 +805,6 @@
expect( Object.class_name_of([]) ).toBe "Array"
expect( Object.class_name_of(new Object([])) ).toBe "Array"
expect( Object.class_name_of(new Array()) ).toBe "Array"
- expect( Object.class_name_of(new Object(true)) ).toBe "Boolean"
it "distinguishes RegExp", ->
expect( Object.class_name_of(/a/) ).toBe "RegExp"
@@ -829,6 +866,28 @@
expect(cn_of b.constructor.__super__ ).toBe "A"
expect( b.constructor.__super__.constructor ).toBe A
expect( b.constructor.__super__.constructor.__super__ ).toBeUndefined()
+
+ it "returns only the last part of nested names", ->
+ class A
+ class A.B
+ expect(Object.class_name_of new A.B).toBe "B"
+
+ it "returns dummy name of a named function expression", ->
+ # http://bonsaiden.github.io/JavaScript-Garden/#function.general
+ C = `function D(){}`
+ expect(Object.class_name_of new C).toBe "D"
+
+ it "faces some problems with IE8", ->
+ cn_of = Object.class_name_of
+ # this is OK
+ expect(cn_of new Error() ).toBe "Error"
+ # IE8 returns "anonymous" for these Error objects
+ expect(cn_of new EvalError() ).toMatch "anonymous|EvalError"
+ expect(cn_of new TypeError() ).toMatch "anonymous|TypeError"
+ expect(cn_of new RangeError() ).toMatch "anonymous|RangeError"
+ expect(cn_of new ReferenceError() ).toMatch "anonymous|ReferenceError"
+ expect(cn_of new SyntaxError() ).toMatch "anonymous|SyntaxError"
+ expect(cn_of new URIError() ).toMatch "anonymous|URIError"
* コメント・質問 [#k42bd4cf]
@@ -854,3 +913,4 @@
ただ今見ると、同じページの 2001〜2014年の、時刻まで出ている表を使う方がより正確な式を作れそうですね。100年以上先のカレンダーが必要になることは少なそうなのであまり気にしなくても良いのでしょうけれど。 -- [武内(管理人)] &new{2013-11-28 (木) 00:06:40};
#comment_kcaptcha
+