var object = {a: 1, b: 2};
console.log('object: has object', _.isObject(object)); //true
console.log('object: has array', _.isArray(object)); //false
console.log('object: has', toString.call(object)); //[object Object]
var object2 = {t: [{a: 1, b: 2}, {c: 3, d: 4}]};
console.log('object2: has object', _.isObject(object)); //true
console.log('object2: has array', _.isArray(object)); //false
console.log('object2: has', toString.call(object2)); //[object Object]
var array = [1, 2];
console.log('array: has object', _.isObject(array)); //true
console.log('array: has array', _.isArray(array)); //true
console.log('array: has', toString.call(array)); //[object Array]
var array2 = [{a: 1, b: 2}, {c: 3, d: 4}];
console.log('array2: has object', _.isObject(array2)); //true
console.log('array2: has array', _.isArray(array2)); //true
console.log('array2: has', toString.call(array2)); //[object Array]
์๋ ํ์ธ์ @afranioce์ ๋๋ค! ๊ทธ๊ฒ์ ๋์๊ฒ ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด๋ค ๋ถ๋ถ์ ๋์ ํ๊ณ ์ถ์ต๋๊น?
์ ํ์ด false๊ฐ ์๋์ด์ผ ํฉ๋๊น?
//using jQuery
jQuery.type ([1, 2]) //array
๋ฌด์จ ๋ง์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง _.isObject([])
๊ฐ false
๋ฐํํด์ผ ํ๋ค๊ณ ์์ํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ฐฐ์ด์ด ๊ฐ์ฅ ํ์คํ ๊ฐ์ฒด์ด๊ธฐ ๋๋ฌธ์ ๊ทธ๋ ์ง ์์ต๋๋ค.
๋๋ ๊ทธ๊ฐ ์ฐพ๊ณ ์์๋ ๊ฒ ๊ฐ์์
__.isPlainObject([1,2]) // ๊ฑฐ์ง
์. ์ข ๋ ๊ตฌ์ฒด์ ์ผ๋ก ๋งํ์ด์ผ ํ๋ค. ๊ทธ๋ isPlainObject์ ๊ฐ์ ๋ฉ์๋๋ฅผ ์ฐพ๊ณ ์์์ต๋๋ค. ๊ฐ์ฌ ํด์.
_.isPlainObject
ํ์คํ +1์
๋๋ค. ์ ์ ๋ผ? ๋๋ฌด ์ ์ฉํฉ๋๋ค!!
+1 ์ ์๋์ง? ๋ฐ์ค์ ๋ค๋ฅธ ๋ฐฉ๋ฒ/๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ๊ทธ๊ฐ ์ฐพ๊ณ ์์๋ ๊ฒ ๊ฐ์์