在JavaScript中,对象的字段始终是“公共(public)的”:functionTest(){this.x_=15;}Test.prototype={getPublicX:function(){returnthis.x_;}};newTest().getPublicX();//usingthegetternewTest().x_;//bypassingthegetter但是您可以通过使用局部变量并使用闭包作为getter来模拟“私有(private)”字段:functionTest(){varx=15;this.getPrivateX=function(){returnx;};}