JavaScript Function Call Methods
In JavaScript, there are two ways to make a function call.
- Directly calling a function: You can directly call a function by using the function name followed by parentheses. For example:
function hello() {
console.log('Hello, world!');
}
hello(); // 调用hello函数
- When a function is a method of an object, it can be called using the dot notation. For example:
var obj = {
sayHello: function() {
console.log('Hello, world!');
}
};
obj.sayHello(); // 调用obj对象的sayHello方法