(1)函数
函数传参
<p> 得到返回结果: </p>
<p id = "demo"></p>
<script>
function xx(a,b){
return a*b;
}
document.getElementById("demo").innerHTML=xx(3,5);
</script>
函数作为方法调用
<script>
var student = {
firstName: "knight",
lastName:"zhou",
fullname : function(){
return this.firstName+" "+this.lastName;
}
}
document.write(student.fullname());
// 打印姓
document.write("<br>");
document.write(student.firstName);
</script>
定义函数的另外一种方式:
vue 中可以直接 bb:function .. 是因为,每个页码export 出去了,实际是在一个obj里。
<!DOCTYPE html>
<body>
<button onclick="obj.bb()"> xx </button>
<!-- <button onclick="aa()"> xx </button> -->
<script>
function aa(){
console.log("菜鸟教程的js函数编写方法....");
}
// 这样定义函数
var obj = {
bb: function(){
console.log("aaa...");
}
}
</script>
</body>
</html>
匿名函数
1-1: 声明一个匿名函数,直接赋值给某一个事件
windon.onload = function(){
alert('hello');
};
3-2: 使用匿名函数表达式。将匿名函数,赋值给一个变量。
var show = function(){
alert('hello');
};
show();