您的位置:首页 > Web前端 > JavaScript

js对象内部访问this修饰的成员函数示例

2014-04-27 11:22 453 查看

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

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  js this 成员函数