//== Class Definitionvar Test = function() { var login = $('#m_login'); //== Private Functions var funaname = function() { login.removeClass('m-login--signin'); } var handleTest = function() { console.log('asdf', 'asdf'); } //== Public Functions return { // public functions init: function() { handleTest(); } };}();//== Class InitializationjQuery(document).ready(function() { Test.init();});
var Player = (function() { // 实例 var instance = null; var login = $('#m_login'); // 私有变量 var hp = 100; // 生命值 var mp = 200; // 魔法值 var handleTest = function() { console.log('aaaaaa', 'aaaaa'); } // 初始化函数 function init() { return { // 获取生命值 getHp: function() { return hp; }, // 获取魔法值 getMp: function() { return mp; }, // 行走方法 run: function() { handleTest(); } } } return { // 初始化一个游戏英雄 getInstance: function() { // 未存在,则初始化 if (!instance) { instance = init(); } return instance; }, run:function () { var app = Player.getInstance(); app.run(); } }})();