当前位置:首页 > JavaScript > 正文内容

jquery.objectize JavaScript 面向对象编程

canca14年前 (2011-06-28)JavaScript322

demo.html

<html>
 <head>
  <title>JQuery 面向对象编程插件</title>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  <style type="text/css">
   .userName{
    color:#00f;
   }
  </style>
  <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
  <script type="text/javascript" src="js/jquery.objectize.js"></script>
  <script type="text/javascript">
   $.include("example.io.Base"); //导入example/io/Base.js
   $.include("example.io.File"); //导入example/io/File.js
   $(function(){
    //定义类方法1:
 /*   var a = $.Class('example.io.Base').New("a","b");
    var b = $.Class('example.io.File').New("c","d");

    //定义类方法2:
    $.Objectize.namespaces();
    var a = example.io.Base.New("a", "b");
    var b = example.io.File.New("c", "d");
     
    //调用类方法
    b.showMsg();
    alert(b.doSomething());

    //判断类类型
    alert(b.is("example.io.Base"));
 */
    $.Class("user.form.Div",{
     Div : function(clsName){
      this.object().attr("class",clsName);
     },
     templet : '<div>${userName}</div>',
     _o : null,
     object : function(){
      if(this._o == null){
       this._o = $(this.templet);
      }
      return this._o;
     },setUserName : function(userName){
      this.object().html(userName);
     }
    });
    $.Class("user.form.UserName","user.form.Div",{
     UserName : function(clsName,data){
      this.Div(clsName);
      this.object().html(data);
     },writeTo : function(elem){
      $(elem).append(this.object());
     }
    });

    var userName = $.Class("user.form.UserName").New("userName","Mr.CT");
    userName.object().click(function(){
     alert($(this).html());
    }).css({"cursor" : "pointer"}).hover(function(){
     $(this).css("color","#ff0000");
    },function(){
     $(this).css("color","#0000ff");
    });
    $(userForm).append(userName.object());
   });
  </script>
 </head>
 <body>
  <div id="userForm">
   
  </div>
 </body>
</html>

 

Base.js

$.Class('example.io.Base', {
 x : 30,
 y : 20,
 watch: function(people){
  return people + "看电视!";
 },
 Base : function( a, b ) {
  alert("Base: " + a+","+b);
 }
});

 

File.js

$.Class('example.io.File','example.io.Base',{
 File : function( a, b ) {
  this.Base(a, b);
 },
 showMsg:function(){
  alert("X:" + this.x + " Y: " + this.y);
 },
 doSomething:function(){
  return this.watch("Mr.CT");
 }
});

扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/236.html

标签: JavaScript
分享给朋友:

“jquery.objectize JavaScript 面向对象编程” 的相关文章

JavaScript 函数原型对象

    以下是一篇本人在Qzone里写下的文章,现在放到这里来,欠丑了。希望对一些初学者有一点点帮助。     今天给大家说说JavaScript中的类。类?没错。JavaScript中的函数原型对象就是OOP中人们熟悉的类。JS...

《Dom Scripting》读书笔记

  《Dom Scripting》读书笔记 Canca         最近看了一本《Jeremy Keith: DOM Scripting, Web design with JavaScript and the DOM. Apr...

javascript MailTo 邮件技巧

调用email的方法 //<a href="mailto:talantlee@126.com">Email</a>window.location.href="mailto:talantlee@126.com";myform.action="mailto:talant...

javascript 中面向对象編程 (类的继承)

// 人的基類var Person=new ( function(){  var sex;  var name;  this.getSex=function() &nbs...

javascript IE与FireFox 一些兼容写法

1>获取控件用document.getElementById,不用document.all(FF等浏览器不支持)2><button> 会被firefox解释为提交form或者刷新页面,需要写标准<button type="button">3>使用childN...

javascript 弹出式窗体详解

1>window.prompt(text, value) 簡單的基與模態窗體的對話框,(返回你輸入)   var v=window.prompt("提示","請輸入你的名字")2>window.confirm(text,mess)  模態確認框(返回"是/否...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。