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

WBOY
Release: 2016-05-16 16:50:58
Original
1264 people have browsed it

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);
}
}

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