类的写法是这样滴:var PopupLayer = new Class({          //表示一个弹出层类,options为设置,_init为初始化函数
    options:{
suibian:"123"
    },
    _init:function(a,b,options){
        jQuery.extend(this.options,options);//合并options
        alert(a + "" + b + this.options.eventType)
    }
});var myPopup = new PopupLayer("ele1","ele2",{  //实例化PopupLayer 类
    eventType:'click'
});我现在的问题是写不来Class类,跪求高手帮忙,可用jquery,大谢!!!!!!!

解决方案 »

  1.   


    (function($) {  var popupLayer = function (a, b, options) {
        this._init(a, b, options);
      };  popupLayer.prototype = 
      {
        _init: function (a, b, options)
        {
           this.options = $.extend(true, {
             suibian: '123',
             eventType: null
           }, options || {});  
           alert(a + '' + b + this.options.eventType)
        }
      })(jQuery);
      

  2.   

    function myFriend(theName, gender, theAge, birthOn) {
      this.name = theName;
      this.isMale = (gender.toLowerCase == 'male');
      this.age = theAge;
      this.birthday = new Date(birthOn);
      function getName(theName){
        return theName
     }
      this.getName=getName(this.name); }
      

  3.   

    xmliy,看清需求,你这种写法我会
      

  4.   

    Class ? 
    印象中好像是Prototype.js框架中才有用到吧
    var popupLayer = Class.create(
    {
      initialize: function(a, b, options)
      {
        this.options = Object.extend({
          suibian: '123',
          eventType: null
        }, options || {});
      }
    });
    这样? 以上需要用到Prototype 1.6
      

  5.   

    mootools也用到Class,我就是要个简化的Class版本
      

  6.   

    因为jquery没有类特性,写东西太烦躁了,习惯mootools
      

  7.   

    function 中包含function你就把函数中又有了函数的那种函数当做类吧
      

  8.   

    just参考,直接把传入的对象绑做返回函数的原形
    var apply = function(s,o,d){
    if(d && typeof d == 'object'){apply(s,d)}
    if(s && o && typeof s == 'object' && typeof o == 'object'){
    for(var i in o){s[i] = o[i]}
    }
    return s;
    }
    var Class = function(init){
    var fn =  function(){
    if(init._init && typeof init._init == 'function'){
    this._init.apply(this,arguments);
    }
    }
    if(typeof init == 'object'){
    fn.prototype = init;
    }
    return fn;
    }
    var PopupLayer = new Class({
    option:{suibian:'123'}
       ,_init:function(a,b,option){
    apply(this.option,option,{suibian2:'234'});
    alert(a+''+b+''+this.option.eventType);
       }
    })
    var myPopup = new PopupLayer("hello","world",{eventType:'click'});
    alert(myPopup.option.suibian2)
      

  9.   

    大哥,弱弱的问下,apply不是js原生方法吗?为什么要
    var apply = function(s,o,d){
        if(d && typeof d == 'object'){apply(s,d)}
        if(s && o && typeof s == 'object' && typeof o == 'object'){
            for(var i in o){s[i] = o[i]}
        }
        return s;
    }
      

  10.   

    没搞jquery,我是EXT流派的,,所以大概写了个属性copy的函数。
    你说的那个apply是Function对象的函数,和我写这个不是一个东西。
      

  11.   

    foolbirdflyfirst,你的方法测试通过,强大啊,待会我结好贴,我新开个帖子,我还要把自定义事件整进Class,你要帮忙喔!