您的位置:首页 > Web前端 > JavaScript

JavaScript入门之函数的高级写法

2014-02-26 15:57 579 查看
1

<html>
<head>
<title>高数高级写法</title>
<script>
function square(x){return x * x};
var f = function(x){return x * x};
alert(f(5));
</script>
</head>
</html>

2
<html>
<head>
<title>高数高级写法</title>
<script>
var f = function square(x){
alert("***");
alert(square);
return x * x;
};
alert(f(5));
</script>
</head>
</html>

结果:
***
f = function square(x){
alert("***");
alert(square);
return x * x;
};
25

先调用函数里面的alert,然后在调用整体。
3.函数调用

<html>
<head>
<title>高数高级写法</title>
<script>
function setValue(x){return x + 10};
var f = function square(x){
return setValue(x) * setValue(x);
};
alert(f(5));
</script>
</head>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: