JavaScript函数的调用(1)
// javascript函数有4种调用方式
// 每种方式的不同方式在于this 的初始化
// this 关键字
// this 指向函数执行时的当前对象
// 一、作为一个函数调用 (不带参数\带参数\函数表达式)
// 不带参数
function a(){
document.write("欢迎来到0133技术站!"+"<br>")
}
a()
// // 带参数
function myFun(a, b) {
return a + b;
}
var x= myFun(10,5)
document.write(x+"<br>")
document.write(myFun(10,5))
// // 函数表达式
var add=function( a,b){
return a*b;
}
document.write(add(10,5)+"<br>")
// //直接调用函数的方式,this指向的全局对象window
// // 二、函数作为方法调用
var myObj={
firstName: "张",
lastName: "三",
fullName: function() {
return this.firstName + this.lastName;
}
}
// document.write(myObj.fullName()+"<br>");
// // 函数作为对象的方法调用,this指向当前的对象