Methods are functions. In JavaScript, a function is a piece of code that needs to be called by name; and a method is a JavaScript function called through an object, that is, a method is a special function.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
A function is an executable javascript code block, which needs to be called by name. It can pass some data (parameters of the function) for processing, and then return some data (return value of the function), or it may not return data.
Method (method) is a javascript function called through an object. In other words, methods are also functions, just special functions.
The function is a method in the object, and the corresponding attribute name is called the method name
For example:
//方法 var person = { name: ‘张三’, getName: function() { console.log(this.name); } }
//函数 var name=‘张三’ function getName () { console.log(this.name); }
[Related recommendations: javascript learning Tutorial】
The above is the detailed content of Are JavaScript methods functions?. For more information, please follow other related articles on the PHP Chinese website!