如题 1. [代码] [JavaScript]代码 var Class = (function() { // Private static attributes. var constants = { host1: 'localhost:8080', host2: 'http://192.168.191.1:8080', } var Test = {}; // 定义了一个静态方法 Test.getConstant =
1. [代码][JavaScript]代码
var Class = (function() { // Private static attributes. var constants = { host1: 'localhost:8080', host2: 'http://192.168.191.1:8080', } var Test = {}; // 定义了一个静态方法 Test.getConstant = function(name) { //获取常量的方法 return constants[name]; } return Test })(); //测试 alert(Class.getConstant('host1'));