[英]client side javascript function
In client side javascript, whats the difference b/w 在客户端javascript中,有什么区别b / w
$(function(){
....
});
and 和
function myFunc() {
...
}
(Could not find relevant tutorials on Google) (无法在Google上找到相关教程)
The first is a DOM ready handler function used in jQuery (a JavaScript library). 第一个是jQuery (JavaScript库)中使用的DOM ready处理函数。 It is executed when the DOM is fully loaded.
在DOM完全加载后执行。 Whereas, the second is a simply defined function with name
myFunc
. 而第二个是名称为
myFunc
的简单定义的函数。
You can read more about JavaScript functions in MDN : https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function . 您可以在MDN中阅读有关JavaScript函数的更多信息: https : //developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function 。
They are totally different uses of function. 它们是功能的完全不同的用途。
The first on calls function $()
with parameter function() {}
. 第一个on函数使用参数
function() {}
函数$()
。
The second defines function myFunc
. 第二个定义函数
myFunc
。
$() is a shorthand for jQuery's document.ready syntax: Documentation $()是jQuery的document.ready语法的简写: 文档
Code inside a $() will run when the dom has loaded enough to be accessed/manipulated. 当dom加载到足以被访问/操作时,$()内的代码将运行。
The second example is just a normal function declaration and creates a function named myFunc that can be called with syntax myFunc()
later. 第二个示例只是一个普通的函数声明,并创建了一个名为myFunc的函数,以后可以使用语法
myFunc()
进行调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.