OO JQuery和类 [英] OO JQuery and classes

查看:74
本文介绍了OO JQuery和类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站并且第一次使用JQuery。我以前的项目主要使用MooTools,而且我使用编写了一些小部件类。 MooTools类结构。我想将它们移植到JQuery,但在我看来,就对象类而言,没有类似于MooTools的功能。

I'm working on a site and using JQuery for essentially the first time. I've mostly used MooTools for previous projects, and I have a few widget classes I've written using the MooTools Class structure. I'd like to port them over to JQuery, but it looks to me like there is nothing similar to the MooTools functionality when it comes to object classes.

我是搜索了一下,并没有找到太多。 Digg似乎有推出自己的,但我不确定这是不是我应该使用的东西。有没有更好的办法?人们通常使用JQuery如何面向对象?什么是封装UI小部件(或任何功能类结构)的常用方法?

I've searched around a bit, and haven't found much on it. Digg appears to have rolled their own, but I'm not sure if this is something I should be using. Is there a better way? How object-oriented do people normally get with JQuery? What's the usual method of encapsulating a UI widget (or any functional class structure)?

我将发布一个可能的MooTools小部件类的假例子:

I'll post a fake example of a possible MooTools widget class:

var ZombatWidget = new Class({
    Extends: BaseWidget,
    widgetPropertyX = 'prop1',
    widgetPropertyY = 'prop2',
    attach = function(el) {
        var f = function() { 
            //do something widgety
        };
        el.addEvent('dblclick',f);
        el.addClass('widgetized');
    }
});

var z = new ZombatWidget();
z.attach($('widgetDiv'));

我得到的东西比那要大很多,但你明白了。我是否需要将其转换为类/继承结构的 prototype 方法?你会如何使用JQuery编写这种对象类?

What I've got is a lot bigger than that, but you get the idea. Do I need to convert this to the prototype method of class/inheritance structuring? How would you write this kind of object class using JQuery?

推荐答案

你可能会发现这种方法对于危险的任务很有用: a href =http://blog.virgentech.com/2009/06/building-object-oriented-jquery-plugin.html =noreferrer>构建面向对象的jquery插件。

You might find this approach useful to the task at stake: building an object-oriented jquery plugin.

这篇关于Ajaxian的文章一个真正的OO类系统jquery

And this article on Ajaxian "a real OO class system with jquery".

这篇关于OO JQuery和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆