jQuery面向对象定制业务框架开发

jbase.js 业务框架基类

/**
* @class: Jbase
* @description: 定制框架基类
* @author: fangxianghua
*/
var Jbase = function() {
  this.namespace = "Jbase";//命名空间
  this.version = "2.0.0"; //版本
  this.parent = null;
  this.className = "Jbase";
};
/**
* @function: extend
* @description: 父子类继承函数
* @author: fangxianghua
*/
Jbase.extend = function (subClass, superClass) {
  var F = function () { };
  F.prototype = superClass.prototype;
  subClass.prototype = new F();
  subClass.prototype.constructor = subClass;

  subClass.parent = superClass.prototype;
  if (superClass.prototype.constructor == Object.prototype.constructor) {
    superClass.prototype.constructor = superClass;
  }
};
//-------------------------常用工具函数定义在基类begin-----------------------------//
//工具函数开发原则:jquery类库中已有的尽量使用其的,否则在此定制相关工具函数
/**
* @function: getKeyCode
* @description: 获取事件转换码
* @author: fangxianghua
* @param: event
* @return: keyCode
*/
Jbase.getKeyCode = function (event) {
  event = (event) ? event : ((window.event) ? window.event : "");
  return event.keyCode ? event.keyCode : event.which;
};


Jbase.showKeyCode = function (event) {
  return event;
};
//-------------------------常用工具函数定义在基类end-----------------------------// 

keyboard.js 基于定制框架基类的业务子类

/**
* @class: Keyboard
* @description: 测试框架类
* @author: fangxianghua
*/
Jbase.Keyboard = function () {
  //------------全局变量----------
  this.className = "Jbase.Keyboard";
  this.stylePath = "../style/default/";
  this.name = "";
  //------------全局变量----------
};
Jbase.extend(Jbase.Keyboard, Jbase);
/**
* @function: Init
* @description: 初始化
* @author: fangxianghua
* @param: null
* @return: null
*/
Jbase.Keyboard.prototype.init = function () {
  this.className = "石英,没来!";
  this.name = "石英";
};
/**
* @function: showKeyboard
* @description: 显示
* @author: fangxianghua
* @param: null
* @return: null
*/
Jbase.Keyboard.prototype.showKeyboard = function () {
  var aa = Jbase.showKeyCode("石英");
  alert(aa);
};
var jbaseKeyboard;
if (jbaseKeyboard == null) {
  jbaseKeyboard = new Jbase.Keyboard();
}
jQuery.extend(jbaseKeyboard); //为了统一使用jQuery框架将定制业务类追加至jQuery静态构造函数中

jQuery_oop.html 调用页面

<html>
<head>
  <title>软键盘</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <meta name="page-view-size" content="1280*720" />
  <link id="settingcss" rel="stylesheet" type="text/css" href="style/default/setting.css" />
  <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
  <script type="text/javascript" src="js/jbase.js"></script>
  <script type="text/javascript" src="js/keyboard.js"></script>
  <script type="text/javascript">
    jQuery(document).ready(function () {
      jQuery.showKeyboard();
    });
  </script>
</head>
<body style="background-color: #ffffff;">
  <div id="main" class="main">
  </div>
</body>
</html>

原文地址:https://www.cnblogs.com/fx2008/p/2299122.html