首页  >  文章  >  web前端  >  js对象内部访问this修饰的成员函数示例_基础知识

js对象内部访问this修饰的成员函数示例_基础知识

WBOY
WBOY原创
2016-05-16 16:50:581257浏览

用wrapper封装这样在对象内外都可以访问

复制代码 代码如下:

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn