javascript属性の検出方法

746 ワード

//    
//in   
var o = {x:1};
var exsit = "x" in o;
alert(exsit);
// hasOwnProperty
exsit = o.hasOwnProperty("x");
alert(exsit);

function inherit(p)
{
	function f(){};
	f.prototype=p;
	return f;
}

// propertyIsEnumerable
var oo = inherit({y:2});

oo.x=1;

var eumn = o.propertyIsEnumerable("x");
alert("    :"+eumn);
eumn = o.propertyIsEnumerable("y");
alert("Is Enumerable :"+eumn);

//  !==       undefined and null

var ooo = {x:1};
var goo = (ooo.x !== undefined);

alert("undefined: " + goo);