9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

カンマ区切りで処理を繋ぐ書き方

Last updated at Posted at 2012-08-23

とあるJSを解析していたところ、下記のような書き方でJSを記述していた。

javascript
var a = (function(){
	var hoge,fuga;
	return hoge = 1, fuga =2 , function(){
		return hoge + fuga;
	}
})();
a();
// >>3

returnの後に処理をカンマで区切って書いている。。
結局は最後に記述した処理がreturnされるのだけど、、、
非常に読みにくい。

素直にこれじゃだめなのか?

javascript
var a = (function(){
	var hoge = 1,
		fuga = 2;
	return function(){
		return hoge + fuga;
	}
})();
a();
// >>3

カンマ区切りのメリットはあるのだろうか。。

9
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?