Home > Web Front-end > Front-end Q&A > Are JavaScript methods functions?

Are JavaScript methods functions?

青灯夜游
Release: 2021-07-06 15:48:40
Original
2231 people have browsed it

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.

Are JavaScript methods functions?

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);
}
}
Copy after login
//函数
var name=‘张三’
function getName () {
console.log(this.name);
}
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template