【メモ】JavaScriptコード仕様-ネーミング仕様
1860 ワード
単一のアルファベット名を避け、名前に記述性を持たせる
オブジェクト、関数、インスタンスの名前を付けるときにラクダスペルを使用
コンストラクション関数またはクラス名の名前を付ける場合は、アルパカ式の書き方を使用します.
プライベート属性の名前を付けるときに下線を引く
この参照を保存するときに使用_this
関数の名前を付けると、次の方法でスタックトラッキングが容易になります.
ファイルがクラスとしてエクスポートされる場合、ファイル名はクラス名と一致する必要があります.
1:15 And let them be for lights in the firmament of the heaven to give light upon the earth:and it was so.
// bad
function q() {
// ...stuff...
}
// good
function query() {
// ..stuff..
}
オブジェクト、関数、インスタンスの名前を付けるときにラクダスペルを使用
// bad
var OBJEcttsssss = {};
var this_is_my_object = {};
function c() {}
var u = new user({
name: 'Bob Parr'
});
// good
var thisIsMyObject = {};
function thisIsMyFunction() {}
var user = new User({
name: 'Bob Parr'
});
コンストラクション関数またはクラス名の名前を付ける場合は、アルパカ式の書き方を使用します.
// bad
function user(options) {
this.name = options.name;
}
var bad = new user({
name: 'nope'
});
// good
function User(options) {
this.name = options.name;
}
var good = new User({
name: 'yup'
});
プライベート属性の名前を付けるときに下線を引く
// bad
this.__firstName__ = 'Panda';
this.firstName_ = 'Panda';
// good
this._firstName = 'Panda';
この参照を保存するときに使用_this
// bad
function() {
var self = this;
return function() {
console.log(self);
};
}
// bad
function() {
var that = this;
return function() {
console.log(that);
};
}
// good
function() {
var _this = this;
return function() {
console.log(_this);
};
}
関数の名前を付けると、次の方法でスタックトラッキングが容易になります.
// bad
var log = function(msg) {
console.log(msg);
};
// good
var log = function log(msg) {
console.log(msg);
};
ファイルがクラスとしてエクスポートされる場合、ファイル名はクラス名と一致する必要があります.
// file contents
class CheckBox {
// ...
}
module.exports = CheckBox;
// in some other file
// bad
var CheckBox = require('./checkBox');
// bad
var CheckBox = require('./check_box');
// good
var CheckBox = require('./CheckBox');
1:15 And let them be for lights in the firmament of the heaven to give light upon the earth:and it was so.