English 中文(简体)
援引职能?
原标题:Passing arguments to a function?
  • 时间:2010-05-31 11:38:41
  •  标签:
  • javascript

我需要了解如何通过联系阵列来履行这一职能,以便我能够在以下职能中做到:

function someName($argums) {
    if (gettype($argums) !=  array  || 
       !array_key_exists( myOneKey , $argums) ||
       !array_key_exists( myOtherKey , $argums)) {              
           return false;
    } 

    /*do other stuff*/
}

(在我所期待的贾瓦文中,我会如何在PHP中这样做)

最佳回答

所有 Java印物体都是相关的阵列,因此确实容易。 您实际上有几种选择,因为物体可拥有自己的特性、其继承的原型、具有未界定价值的特性和具有“falsey”价值的特性(<条码>未界定的、<代码>null、0<>>>>>、或当然还有false。 (物体没有 财产与未确定价值者之间的差额)

检查物体是否具有特性: 请注意:

function someName(obj) {
    if (!obj ||
        !obj.hasOwnProperty( myOneKey ) ||
        !obj.hasOwnProperty( myOtherKey ))
        return false;
    }
    // Do other stuff
}

检查物体是否拥有财产? 通过原型: 页: 1

function someName(obj) {
    if (!obj ||
        !( myOneKey  in obj) ||
        !( myOtherKey  in obj))
        return false;
    }
    // Do other stuff
}

检查物体是否拥有(直接或通过原型)并且未界定: 2. 你们期望的是未界定的价值:

function someName(obj) {
    if (!obj ||
        typeof obj.myOneKey === "undefined" ||
        typeof obj.myOtherKey === "undefined")
        return false;
    }
    // Do other stuff
}

检查财产是否伪造(un Defin,null,0,>,或当然,false,不论为何: Just use!:

function someName(obj) {
    if (!obj ||
        !obj.myOneKey ||
        !obj.myOtherKey)
        return false;
    }
    // Do other stuff
}

不管怎样使用:

var obj = {
    myOneKey:  fred ,
    myOtherKey:  barney 
};
someName(obj);
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签