Skip to content

Commit 121cbac

Browse files
committed
Updated Japanese translation
1 parent aceba65 commit 121cbac

File tree

1 file changed

+186
-18
lines changed

1 file changed

+186
-18
lines changed

translations/ja_JP/readme.md

Lines changed: 186 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 一貫性のある慣用的なJavaScriptの書き方
22

3+
34
## これは継続しているドキュメントであるため、私たちのコードを改善できる新しいアイデアを常に歓迎します。貢献方法: fork、clone、branch、commit、push、pull request。
45

56
* Rick Waldron [@rwaldron](http://twitter.com/rwaldron), [github](https://github.com/rwldrn)
@@ -16,27 +17,40 @@
1617
* Ryuichi Okumura [@okuryu](http://twitter.com/okuryu), [github](https://github.com/okuryu)
1718
* Pascal Precht [@PascalPrecht](http://twitter.com/PascalPrecht), [github](https://github.com/pascalprecht)
1819
* EngForDev [engfordev](http://www.opentutorials.org/course/167/1363) - Hwan Min Hong / MinTaek Kwon [@leoinsight](http://twitter.com/leoinsight) / Tw Shim [@marocchino](http://twitter.com/marocchino), [github](https://github.com/marocchino) / Nassol Kim [@nassol99](http://twitter.com/nassol99), [github](https://github.com/nassol) / Juntai Park [@rkJun](http://twitter.com/rkJun), [github](https://github.com/rkJun) / Minkyu Shim / Gangmin Won / Justin Yoo [@justinchronicle](http://twitter.com/justinchronicle) / Daeyup Lee
20+
* Marco Trulla [@marcotrulla](http://twitter.com/marcotrulla), [github](https://github.com/Ragnarokkr)
21+
* Alex Navasardyan [@alexnavasardyan](http://twitter.com/alexnavasardyan), [github](https://github.com/2k00l)
22+
1923

2024
## どんなに多くの人が貢献したとしても、どのコードも一人で書いたようにするべきです。
2125

2226
### 次の項目では私のすべてのコードで使用しているプラクティスを説明しているため、私のプロジェクトに貢献する場合はこれらのガイドラインを理解していなければなりません。
2327

24-
### 私は皆さんのコードに私のスタイルを押し付けるつもりはありませんし、もしすでに共通のスタイルがあるのであればそちらを順守すべきです。
28+
### 私は皆さんのコードやプロジェクトに私のスタイルを押し付けるつもりはありませんし、もしすでに共通のスタイルがあるのであればそちらを順守すべきです。
29+
2530

26-
> "成功を収めるプロジェクトをうまく管理することの一つが自分でコードを書いて実現するということではありません。もし多くの人があなたのコードを利用しているなら、仕様の中にはあなたの好みではなく、最大限に明確なコードを書きましょう。" - Idan Gazit
31+
> ### "スタイルに関する議論は無意味です。ここにあるスタイルガイドにあなたは従うべきです。"
32+
>_Rebecca_ _Murphey_
2733
34+
 
35+
36+
> ### "成功を収めるプロジェクトをうまく管理することの一つが自分でコードを書いて実現するということではありません。もし多くの人があなたのコードを利用しているなら、仕様の中にはあなたの好みではなく、最大限に明確なコードを書きましょう。" - Idan Gazit
37+
>_Idan_ _Gazit_
2838
2939
## 翻訳
3040

41+
* [ドイツ語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/de_DE)
3142
* [フランス語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/fr_FR)
3243
* [スペイン語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/es_ES)
3344
* [ポルトガル語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/pt_BR)
3445
* [韓国語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/ko_KR)
3546
* [日本語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/ja_JP)
47+
* [イタリア語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/it_IT)
48+
* [ロシア語](https://github.com/rwldrn/idiomatic.js/tree/master/translations/ru_RU)
49+
3650

3751
## 慣用的ではないもの(重要):
3852

39-
### コードの品質: 素晴らしいツールや情報とリファレンス
53+
### コードの品質ツールや情報とリファレンス
4054

4155
* [jsPerf](http://jsperf.com/)
4256
* [jsFiddle](http://jsfiddle.net/)
@@ -45,12 +59,11 @@
4559
* [jshint](http://jshint.com/)
4660
* [jslint](http://jslint.org/)
4761

48-
[Anton KovalyovによるLeveraging Code Quality Tools](http://anton.kovalyov.net/slides/gothamjs/)
49-
5062

51-
### 賢くなろう
63+
## 賢くなろう
5264

53-
[http://es5.github.com/](http://es5.github.com/)
65+
### [Annotated ECMAScript 5.1](http://es5.github.com/)
66+
### [EcmaScript Language Specification, 5.1 Edition](http://ecma-international.org/ecma-262/5.1/)
5467

5568
下記の事項は 1) 不完全、2) *必読*ということを熟考しなければなりません。私はこれらの作者によるスタイルに常に同意はしていませんが、彼らは一貫性があるため信頼できるのも確かです。その上、これらは言語の世界では権威があるものです。
5669

@@ -61,6 +74,9 @@
6174
* [Perfection Kills](http://perfectionkills.com/)
6275
* [Douglas Crockford's Wrrrld Wide Web](http://www.crockford.com)
6376
* [JS Assessment](https://github.com/rmurphey/js-assessment)
77+
* [Leveraging Code Quality Tools by Anton Kovalyov](http://anton.kovalyov.net/slides/gothamjs/)
78+
79+
6480

6581

6682
### ビルドとデプロイのプロセス
@@ -446,7 +462,7 @@
446462
```
447463

448464

449-
```js
465+
```javascript
450466
451467
// 3.B.1.1
452468
@@ -821,13 +837,13 @@
821837
6. <a name="naming">ネーミング</a>
822838

823839

824-
あなたがコードをコンパイルしたり圧縮したりするわけではないので、そういった事をしようとしてはいけません。
840+
A. あなたがコードをコンパイルしたり圧縮したりするわけではないので、そういった事をしようとしてはいけません。
825841

826842
次のコードはひどいネーミングの例です:
827843

828844
```javascript
829845
830-
// 6.1.1
846+
// 6.A.1.1
831847
// 悪い名前を使ったコードの例
832848
833849
function q(s) {
@@ -843,7 +859,7 @@
843859

844860
```javascript
845861
846-
// 6.2.1
862+
// 6.A.2.1
847863
// 改善したネーミングを使ったコードの例
848864
849865
function query( selector ) {
@@ -855,7 +871,7 @@
855871
matches = query("#foo"),
856872
length = matches.length;
857873
858-
for( ; idx < length; idx++ ){
874+
for ( ; idx < length; idx++ ) {
859875
elements.push( matches[ idx ] );
860876
}
861877
@@ -865,37 +881,37 @@
865881

866882
```javascript
867883
868-
// 6.3.1
884+
// 6.A.3.1
869885
// 文字列のネーミング
870886
871887
`dog` は文字列です
872888
873889
874-
// 6.3.2
890+
// 6.A.3.2
875891
// 配列のネーミング
876892
877893
`dogs``dog` という文字列の配列です
878894
879895
880-
// 6.3.3
896+
// 6.A.3.3
881897
// 関数、オブジェクト、インスタンスなどのネーミング
882898
883899
camelCase; function と var による宣言
884900
885901
886-
// 6.3.4
902+
// 6.A.3.4
887903
// コンストラクターやプロトタイプなどのネーミング
888904
889905
PascalCase; コンストラクター
890906
891907
892-
// 6.3.5
908+
// 6.A.3.5
893909
// 正規表現のネーミング
894910
895911
rDesc = //;
896912
897913
898-
// 6.3.6
914+
// 6.A.3.6
899915
// Google Closure Library Style Guideより
900916
901917
functionNamesLikeThis;
@@ -905,10 +921,162 @@
905921
methodNamesLikeThis;
906922
SYMBOLIC_CONSTANTS_LIKE_THIS;
907923
924+
```
925+
926+
B. `this` の扱い
927+
928+
後から呼び出される `BoundFunction` を定義する場合は `call``apply` の一般的な使われ方よりも `.bind( this )` や同等の機能が好ましいです。好ましいオプションがない場合だけ、別の方法を考えましょう。
929+
930+
```javascript
931+
932+
// 6.B.1
933+
function Device( opts ) {
934+
935+
this.value = null;
936+
937+
// これは非同期のストリームをオープンし
938+
// 継続的に呼び出されます
939+
stream.read( opts.path, function( data ) {
940+
941+
// このインスタンスの現在の値を
942+
// データストリームの最新の値で更新します
943+
this.value = data;
944+
945+
}.bind(this) );
946+
947+
// デバイスのインスタンスから頻繁に発行される
948+
// イベントを絞ります
949+
setInterval(function() {
950+
951+
// 絞ったイベントを発行します
952+
this.emit("event");
953+
954+
}.bind(this), opts.freq || 100 );
955+
}
956+
957+
// EventEmitterを継承したかのように装います ;)
958+
959+
```
960+
961+
もし利用できない場合でも最近の多くのJavaScriptライブラリには `.bind` と同様な機能があります。
962+
963+
964+
```javascript
965+
// 6.B.2
966+
967+
// 例)lodash/underscoreの_.bind()
968+
function Device( opts ) {
969+
970+
this.value = null;
971+
972+
stream.read( opts.path, _.bind(function( data ) {
973+
974+
this.value = data;
975+
976+
}, this) );
977+
978+
setInterval(_.bind(function() {
979+
980+
this.emit("event");
981+
982+
}, this), opts.freq || 100 );
983+
}
984+
985+
// 例)jQuery.proxy
986+
function Device( opts ) {
987+
988+
this.value = null;
989+
990+
stream.read( opts.path, jQuery.proxy(function( data ) {
991+
992+
this.value = data;
993+
994+
}, this) );
908995
996+
setInterval( jQuery.proxy(function() {
997+
998+
this.emit("event");
999+
1000+
}, this), opts.freq || 100 );
1001+
}
1002+
1003+
// 例)dojo.hitch
1004+
function Device( opts ) {
1005+
1006+
this.value = null;
1007+
1008+
stream.read( opts.path, dojo.hitch( this, function( data ) {
1009+
1010+
this.value = data;
1011+
1012+
}) );
1013+
1014+
setInterval( dojo.hitch( this, function() {
1015+
1016+
this.emit("event");
1017+
1018+
}), opts.freq || 100 );
1019+
}
1020+
1021+
```
1022+
1023+
最後の回避方法は、識別子として`this`への別名に`self`を使うことですが、これは極端なバグになる傾向があるため、可能な限り避けるべきです。
1024+
1025+
```javascript
1026+
1027+
// 6.B.3
1028+
1029+
function Device( opts ) {
1030+
var self = this;
1031+
1032+
this.value = null;
1033+
1034+
stream.read( opts.path, function( data ) {
1035+
1036+
self.value = data;
1037+
1038+
});
1039+
1040+
setInterval(function() {
1041+
1042+
self.emit("event");
1043+
1044+
}, opts.freq || 100 );
1045+
}
1046+
1047+
```
1048+
1049+
1050+
C. `thisArg`を使う
1051+
1052+
ES 5.1の各プロトタイプのメソッドでは特別な`thisArg`という署名に対応しています。これは可能な限り利用するべきです。
1053+
1054+
```javascript
1055+
1056+
// 6.C.1
1057+
1058+
var obj;
1059+
1060+
obj = { f: "foo", b: "bar", q: "qux" };
1061+
1062+
Object.keys( obj ).forEach(function( key ) {
1063+
1064+
// |this|は`obj`への参照
1065+
1066+
console.log( this[ key ] );
1067+
1068+
}, obj ); // <-- 最後の引数が`thisArg`
1069+
1070+
// 結果は...
1071+
1072+
// "foo"
1073+
// "bar"
1074+
// "qux"
9091075
9101076
```
9111077

1078+
`thisArg``Array.prototype.every``Array.prototype.forEach``Array.prototype.some``Array.prototype.map``Array.prototype.filter`と一緒に利用できます。
1079+
9121080
7. <a name="misc">雑則</a>
9131081

9141082
このセクションは偏見的と見なされるべきではないアイデアやコンセプトを説明する代わりに、一般的なプログラミングタスクを行うためのより良い方法を見つけるためのプラクティスを助長するものです。

0 commit comments

Comments
 (0)