js實現呼叫的兩種方式(1.呼叫函式 2.呼叫方法)
阿新 • • 發佈:2019-10-09
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" > /* *實現呼叫的兩種方式 * 1.呼叫方法 * 2.呼叫函式 * */ var obj={ name:"小明", age:18 } //1、呼叫方法 obj.sayHello=function(){ console.log(obj.name) } obj.sayHello(); //2.呼叫函式 function fun(){ console.log(obj.name) } fun(); </script> </head> <body> </body