Mar 6, 2010

how to test whether a object has member

Object.prototype.hasMember = function (memberName)
    return memberName in this;

var attrFn = {
    val: 1,
    css: 2,
    html: 3,
    text: 4,
    data: 5,
    width: 6,
    height: 7,
    offset: 8

don't use attrFn["val"], because is possible that you defined a member
attFn = { val : undefined }, in val is a member but its value is null,
this function also traverse the prototype chain, if you want to check direct member only use "hasOwnProperty".

1 comment:

  1. Players can also win free spins inside every individual recreation. Predict where the ball will land on the wheel and potentially win 빅카지노 a large prize. By taking part in} free of charge you can to|you probably can} absolutely be taught the table format.