javascript之函数1
source link: https://zwkang.com/?p=306
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
函数的三种基本创建方法有:
1、函数声明式
function functionName(arg){
//函数体
}
函数声明式重要特征是函数声明提升 这个的意思是在执行函数代码前会读取函数声明 所以函数声明可以放在调用语句后面
2、函数表达式
var functionName = function(arg0){
//函数体
}
这种创建方法是比较常见的用匿名函数创建并赋值给一个变量的方法
注意 函数表达式是没有提升的 意味着如果你函数表达式语句前调用函数是会错误的
3、var functionName=new Function('arg1','arg2','return arg1+arg2');
这种方法一般很少使用因为频繁Function()构造函数去创建函数效率太低了
Comments
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK