您可以做到,但缺点是它不能成为原型的一部分:
function Restaurant() { var myPrivateVar; var private_stuff = function() { // only visible inside Restaurant() myPrivateVar = "I can set this here!"; } this.use_restroom = function() { // use_restroom is visible to all private_stuff(); } this.buy_food = function() { // buy_food is visible to all private_stuff(); }}


