Fork me on GitHub

javascript访问级别

JavaScript中没有官方的访问级别语法,JavaScript没有类似于Java语言智能搞得private或protected这样的访问级别关键字,默认情况下,,对象中所有的成员都是公有和可访问的,但在JavaScript中可以实现与私有或专有属性类似的访问级别效果。实现私有方法或属性,请使用闭包:

function test(){

  //私有成员

  var destination = "test";

  this.getDestination = function(){

    return destination;

  }

}

var deloren = new test();

console.log(deloren.getDestination());

posted @ 2015-12-10 18:03  CangoWu  阅读(176)  评论(0编辑  收藏  举报