;(function (global, $, doc) {
‘use strict’;
var Application = function () {
this.a = 1,
this.b = 2,
this.eventsMap = {
“click #btnOne”: “funcOne”,
“click #btnTwo”: “funcTwo”
}
this.initEvent();
};
Application.prototype = {
constructor: ‘Application’,
funcOne: function () {
console.log(‘You are clicked btn one!’);
},
funcTwo: function () {
console.log(‘You are clicked btn two!’);
}
};
global.Application = Application;
$(function () {
new Application()
});
})(this, jQuery, jQuery(document));
initEventsMap: function (maps) {
var matchExp = /^(\w+)\s*(.*)$/;
for (var keys in constMap) {
if (maps.hasOwnProperty(keys)) {
var matchResult = keys.match(matchExp);
doc.on(matchResult[1], matchResult[2], this[maps[keys]].bind(this))
// 原型为 document.on(event, element, function)
}
}
}
this.selectMap = {
“idELement”: ‘#element’,
“classElement”: “.head .page-title”
}
initSelector (maps) {
for(var keys in maps) {
if (maps.hasOwnProperty(keys)) {
this[keys] = $(maps[keys])
}
}
}
原文:https://www.cnblogs.com/miku561/p/12449977.html