Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between javascript objects and functions

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "what are the differences between javascript objects and functions". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn "what's the difference between javascript objects and functions"?

Differences: 1, the JavaScript object is a container of variables, which can encapsulate functions, while functions are designed to perform specific tasks of code blocks; 2, JavaScript objects can not encapsulate the operation process, while the JavaScript function can encapsulate the operation process.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

What is the difference between a javascript object and a function

1. Object

The "JavaScript" object is a container for variables, but usually we think of it as a container for key-value pairs, which are usually written as name:value (keys and values are separated by colons).

Key-value pairs are often called object properties in javaScript objects.

Example:

Var person = {firstName: "zhang", lastName: "erga", fullName: function () {return this.firstName + "" + this.lastName;}

two。 Function

The function (method Function) is the encapsulation of the js operation process. To operate the same process later, you only need to call the corresponding function (method). Objects are also encapsulated in js code, but objects can encapsulate functions (methods). For example, encapsulate a certain class of functions (methods) into an object. This allows the management of the system to call functions (methods).

Example:

Function sum (num1, num2) {return num1 + num2;}

3. contact

Functions can be encapsulated in an object.

Example:

Var person = {firstName: "zhang", lastName: "erga", fullName: function () {return this.firstName + "" + this.lastName;}

4. Difference

The object contains and can only be key-value pairs (the key-value is divided by ":", and the value content includes ordinary variables and functions).

The operation process can be encapsulated in the function, but not in the object.

At this point, I believe you have a deeper understanding of "what is the difference between javascript objects and functions?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report