Possible Duplicate:
Javascript: var functionName = function() {} vs function functionName() {}
我很想知道,在js创造职能时,这是最好的预兆。
function x() {
...
}
页: 1
var x = function() {
...
}
是否存在差别,或者这些差别完全相同。
Possible Duplicate:
Javascript: var functionName = function() {} vs function functionName() {}
我很想知道,在js创造职能时,这是最好的预兆。
function x() {
...
}
页: 1
var x = function() {
...
}
是否存在差别,或者这些差别完全相同。
x(); // I work
function x() {
...
}
y(); // I fail
var y = function() {
...
}
第一项是职能声明。 在你宣布之前,你可以行使职能。
第二是将职能分配到一个变量。 这意味着你可以做任何事情。
您可将其编成foo[0]
或foo.bar.baz
或foo.get(”baz”)[0]
。
I prefer the first form because it gets defined before variables are defined.
So, you could invoke x
in a later scope because the interpreter already defined that function even though it may be declared later on in your code.
这将更简单一些法典:
x(); //logs "hi"
//...
function x() {
console.log("hi");
}
v
x(); //fails
var x = function() {
console.log("hi");
};
这些人并非完全一样,他们提到了前方的分歧,这里的微妙之处——功能名称:
function x(){}
x.name; // "x"
var x = function(){};
x.name; // ""
在第二种情况下,你可以把职能作为参数,将其储存在阵列中。
You might find this useful: https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope
第一项职能是申报<>,后一项职能是表示/>。 阅读更多here,而我试图在阅读关于差异和所涉问题时发现一个非常深入的第一条。
Edit: Ah, here we go. Grab a cup of tea and settle in for an in-depth discussion.
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.
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 ...
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 ...
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 ...
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 ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
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.