2017-12-07
//関数の存在確認
console.log(typeof fnc); // undefined
var fnc = function(){};
console.log(typeof fnc); // function
if(typeof fnc == "function"){
console.log("関数が存在する場合の処理");
}
//オブジェクトの存在確認
var obj = {};
if(typeof obj == "object"){
console.log("オブジェクトが存在する場合の処理");
}
//オブジェクトのプロパティの存在確認
console.log(obj.hasOwnProperty('foo')); // false
obj.foo = function(){};
console.log(obj.hasOwnProperty('foo')); // true
if(obj.hasOwnProperty('foo')){
console.log("オブジェクトのプロパティが存在する場合の処理");
}
Categorised in: