Home Web Front-end JS Tutorial Example of accessing this-modified member function inside a js object_Basic knowledge

Example of accessing this-modified member function inside a js object_Basic knowledge

May 16, 2016 pm 04:50 PM
js object member function

Use wrapper to encapsulate it so that it can be accessed both inside and outside the object

Copy code The code is as follows:

function MapPool(){

function createMarker(name, lat, lng, state){
var marker = new AMap.Marker({
position : new AMap.LngLat(lng, lat),
});
//the function mapMoveTo is not accessible here too
AMap.event.addListener(marker, "click",function(e){
//moveMapTo(key, name, state)
//or this.moveMapTo(key, name, state) will raise an unresolved function error
//you should write wrapper function as a member variable
_mapMoveTo(key, name, state);
});
}

var _mapMoveTo = function(key, name, state){
//TODO
}

this.mapMoveTo = function(key, name, state) {
_mapMoveTo(key, name, state);
}
}

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of C++ member functions: error handling and exception mechanism of object methods Detailed explanation of C++ member functions: error handling and exception mechanism of object methods Apr 29, 2024 pm 01:54 PM

The error handling mechanisms in C++ member functions include error codes, assertions and exception mechanisms. The error code directly returns the error value; the assertion checks the assumption and throws an exception if it is not true; the exception captures serious errors and handles them through try-catch blocks. In a practical case, the push_back() function of the Vector class throws a std::bad_alloc exception when the capacity is insufficient. The user can catch and handle the exception through try-catch.

Detailed explanation of C++ member functions: container compatibility and iterator support for object methods Detailed explanation of C++ member functions: container compatibility and iterator support for object methods Apr 29, 2024 pm 01:00 PM

Member functions are functions defined in the context of a class and associated with an object, and can access object data and methods. To make it compatible with containers, a custom class must provide assignment operators, equality and inequality operators, and comparison operators. Additionally, to support iterators, classes should provide begin() and end() functions that return iterators to the starting and ending elements of the container, as well as operators that dereference and increment iterators.

Detailed explanation of C++ member functions: overloading and polymorphism of object methods Detailed explanation of C++ member functions: overloading and polymorphism of object methods Apr 30, 2024 am 08:48 AM

Member function overloading allows functions with the same name to be defined for the same class, distinguished by parameter and return value types. Polymorphism allows derived class objects to exhibit different behaviors by inheriting base class methods. When the base class reference points to a derived class object, calling the base class method will execute the derived class implementation that matches the object type. Overloading and polymorphism play a vital role in the implementation of the instruction set of the virtual machine. Overloading supports different operations based on the instruction type, while polymorphism supports different types of instructions to exhibit different behaviors.

Detailed explanation of C++ member functions: memory management and life cycle of object methods Detailed explanation of C++ member functions: memory management and life cycle of object methods Apr 29, 2024 pm 02:12 PM

Member function memory management and life cycle: Memory allocation: Member functions allocate memory when the object is created. Object life cycle: member functions are bound to the object, created when the object is created, and destroyed when the object is destroyed. Constructor: called when an object is created to initialize data. Destructor: called when an object is destroyed to release resources.

Does C++ function overloading apply to member functions? Does C++ function overloading apply to member functions? Apr 13, 2024 pm 06:15 PM

Yes, function overloading works for member functions, subject to the following restriction: The overloaded member function must have a different parameter signature (type and number). Overloaded member functions cannot have the same return type and different parameter signatures.

C++ syntax error: const-modified member functions must declare const members, how to deal with it? C++ syntax error: const-modified member functions must declare const members, how to deal with it? Aug 22, 2023 pm 01:51 PM

C++ syntax error: const-modified member functions must declare const members, how to deal with it? In the C++ language, const is a very important keyword, which is used to modify certain variables, pointers, member functions, etc. For member functions, if it is modified with the const keyword, the value of the member variable cannot be modified inside the function body. However, if we do not add the const keyword in both the function declaration and definition, we will encounter a compilation error "The const-modified member function must be declared

C++ syntax error: non-const member functions cannot be called with const objects, what should I do? C++ syntax error: non-const member functions cannot be called with const objects, what should I do? Aug 22, 2023 pm 01:57 PM

C++ is a very powerful programming language, but when learning and using C++, we will inevitably encounter some problems. One of the problems that often troubles beginners is the error message "Non-const member functions cannot be called with const objects." In this article, we will explore how to deal with this error. First, to understand this error message, we need to know some basic knowledge. There is the const keyword in C++, which can be used to modify variables, pointers and function parameters, indicating that these objects cannot be modified. exist

What is a constructor? Detailed explanation of constructors in JavaScript What is a constructor? Detailed explanation of constructors in JavaScript Aug 04, 2022 pm 03:22 PM

As the basis of prototypes and prototype chains, first understanding the constructor and its execution process can better help us learn the knowledge of prototypes and prototype chains. This article will take you to learn more about the constructor in JavaScript and introduce how to use the constructor to create a js object. I hope it will be helpful to you!

See all articles