Get the App
SLTechnology News&Howtos  ›  Development  › 

What's the difference between javascript's method and function?

Shulou Source: shulou.com Published: 2022-06-03 17:33:19 10月28日 Update

This article mainly explains the "javascript method and function what is the difference", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "what is the difference between javascript method and function"!

1. If a method is bound to an object, it cannot be referenced separately and can only be called through the object.

2. The function is independent and can be referenced separately.

3. In a method, this represents the object to which the method belongs. In the function, this represents the whole object.

Example

/ / example 1:var person = {name:'leaf'; age:26; getName:function () {console.log (this.name);}} person.getName (); / / leaf// example 2:function demo () {console.log ("I am a function", this);} demo () Thank you for your reading, the above is the content of "what is the difference between javascript method and function". After the study of this article, I believe you have a deeper understanding of the difference between javascript method and function, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Methods functions objects learning examples content representatives functions examples that is ideas situations ownership whole articles more knowledge knowledge points articles follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi vpn Microsoft Linux