JavaScript 4©2ch.net (398レス)
JavaScript 4©2ch.net http://mevius.5ch.net/test/read.cgi/tech/1417749547/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
レス栞
76: デフォルトの名無しさん [sage] 2015/02/18(水) 22:43:31.46 ID:M4E75IrS >>75 null(undefined)チェックを忘れた… function test(hoge, foo) { 'use strict'; if (!hoge) return; if (typeof hoge === 'boolean') { console.log('hoge is', hoge); } else if (typeof hoge === 'object') { if (hoge.hasOwnProperty('hoge') && typeof hoge.hoge === 'boolean') { console.log('hoge is', hoge.hoge); } if (hoge.hasOwnProperty('foo') && typeof hoge.foo === 'boolean') { console.log('foo is', hoge.foo); } } } test(true, false); test({hoge: true, foo: false}); test({hoge: 2}); test({hage: 2}); test(null); test(undefined); test([]); test({hoge:[]}); 単にnullチェック抜けてるって言えば済む問題を○型が考慮されてないとか お前の方が素人丸出しだ http://mevius.5ch.net/test/read.cgi/tech/1417749547/76
79: デフォルトの名無しさん [sage] 2015/02/18(水) 23:52:45.07 ID:86t2mSil >>76 これそもそも第2引数は一度も使ってないけど、何のためにあんの? あと、 if (!hoge) return; 追加したら test(false,false); の時の挙動変わってんじゃん http://mevius.5ch.net/test/read.cgi/tech/1417749547/79
85: デフォルトの名無しさん [sage] 2015/02/19(木) 08:45:08.63 ID:ACeVxkIV >>76 > 単にnullチェック抜けてるって言えば済む問題を○型が考慮されてないとか > お前の方が素人丸出しだ そのコードは typeof 演算子の "Object (native and does not implement [[Call]])" しか対応できてないだろう? http://es5.github.io/#x11.4.3 前方互換性をふまえれば、ES6 でも正しく判定出来ることが望ましい http://people.mozilla.org/~jorendorff/es6-draft.html#sec-typeof-operator Null 型を誤検知するだけなら「Object 型の一部」とはいわない あなたは ECMAScript 仕様書をまともに読んだことがないだろう? ES 仕様に言及している意見に反論するなら仕様書ぐらい読んで欲しい >>78 > >>65 はそもそも何を持って配列のようなオブジェクトといいたいのだろう わかりやすくいうならば、 Array.prototype.forEach と同様の判定といえるかな Array.prototype.forEach では ToObject, ToInt32 で型変換しているわけだが、型変換せずに TypeError を返したい状況もあるだろう http://es5.github.io/#x15.4.4.18 http://mevius.5ch.net/test/read.cgi/tech/1417749547/85
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.013s