var config = {
Redis: {
Host: 'LocalHost'
}
}
//-------------------------------------------
var a = config.Redis;
var b = config.Chat;
console.dir(a); // { Host: 'LocalHost' }
console.dir(b); // undefined
//-------------------------------------------
var c = config.Redis || 'Redis';
var d = config.Chat || 'Chat';
console.dir(c); // { Host: 'LocalHost' }
console.dir(d); // 'Chat'
//-------------------------------------------
var e = config.Redis && 'Redis';
var f = config.Chat && 'Chat';
console.dir(e); // 'Redis'
console.dir(f); // undefined
//-------------------------------------------
var g = config.Redis && config.Redis.Host;
var h = config.Chat && config.Chat.Port;
console.dir(g); // 'LocalHost'
console.dir(h); // undefined
//-------------------------------------------
var i = (config.Redis && config.Redis.Host) || 'google.com';
var j = (config.Chat && config.Chat.Port) || 80;
console.dir(i); // 'LocalHost'
console.dir(j); // 80
'JavaScript' 카테고리의 다른 글
ES2015 에 대하여 (0) | 2016.03.03 |
---|---|
Promise 사용법 (0) | 2015.12.21 |
if문에서 Array.prototype.indexOf() 응용하기 (0) | 2015.11.23 |
Function 객체의 Methods 소개 (0) | 2015.11.23 |
C#에서 JSON 변환하기 (0) | 2015.11.19 |