Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery和Mootools的不可知Javascript框架适配器?_Javascript_Jquery_Language Agnostic_Mootools - Fatal编程技术网

jQuery和Mootools的不可知Javascript框架适配器?

jQuery和Mootools的不可知Javascript框架适配器?,javascript,jquery,language-agnostic,mootools,Javascript,Jquery,Language Agnostic,Mootools,我将把我的一系列jQuery项目移植到香草Javascript(纯Javascript,无框架)上,我想知道是否有任何现有的[framework adapters/框架不可知适配器] 例如,我设想这样的事情: // My Project (function(){ // Fetch all the elements using Sizzle Selector System var $els = Agnostic.find('.penguins'); $els.hide();

我将把我的一系列jQuery项目移植到香草Javascript(纯Javascript,无框架)上,我想知道是否有任何现有的[framework adapters/框架不可知适配器]

例如,我设想这样的事情:

// My Project
(function(){
    // Fetch all the elements using Sizzle Selector System
    var $els = Agnostic.find('.penguins');
    $els.hide();

    // Perform a Ajax Request
    Agnostic.ajax({
        dataType: 'json',
        sucess: function(){

        },
        error: function(){

        }
    });
});

/**
 * Our Agnostic Framework
 * Provides a framework agnostic interface for jQuery and MooTools
 */
var Agnostic = {
    framework: null,
    Framework: null,

    /**
     * Initialise our Agnostic Framework
     */
    init: function(){
        switch ( true ) {
            case Boolean(jQuery||false):
                Agnostic.Framework = jQuery;
                Agnostic.framework = 'jQuery';
                break;

            case Boolean(MooTools||false):
                // Check for Sizzle
                if ( typeof Sizzle === 'undefined' ) {
                    throw new Error('MooTools interface requires the Sizzle Selector Engine.');
                }
                Agnostic.Framework = MooTools;
                Agnostic.framework = 'MooTools';
                break;

            default:
                throw new Error('Could not detect a framework.');
                break;
        }
    }

    /**
     * Our Element Object
     * Used to Wrap the Framework's Object to provide an Agnostic API
     */
    Element: {
        /**
         * Create the Element Wrapper
         */
        create: function(Object){
            var El = new Agnostic.Element;
            El.Object = Object;
        },

        /**
         * Hide the Element
         */
        hide: function(){
            switch ( Agnostic.framework ) {
                case 'jQuery':
                    this.Object.hide();
                    break;

                case 'MooTools':
                    this.Object.setStyle('display','none'); 
                    break;
            }
        },

        /**
         * Show the Element
         */
        show: function(){
            switch ( Agnostic.framework ) {
                case 'jQuery':
                    this.Object.show();
                    break;

                case 'MooTools':
                    this.Object.setStyle('display',''); 
                    break;
            }
        }
    },

    /**
     * Fetch elements from the DOM using the Sizzle Selector Engine
     */
    find: function(selector){
        var Element = null;

        // Fetch
        switch ( Agnostic.framework ) {
            case 'jQuery':
                Element = jQuery(selector);
                break;

            case 'MooTools':
                Element = new Elements(new Sizzle(selector)); 
                break;
        }

        // Wrap
        Element = Agnostic.Element.create(Element);

        // Return Element
        return Element;
    },

    /**
     * Perform an Ajax Request
     * We use the jQuery.ajax interface here
     * But they are more or less the same
     */
    ajax: function(request){
        // Send Request
        switch ( Agnostic.framework ) {
            case 'jQuery':
                jQuery.ajax(request);
                break;

            case 'MooTools':
                (new Request(request)).send();
                break;
        }

        // Wrap
        Element = Agnostic.Element.create(Element);

        // Return Element
        return Element;
    }
};

我还没有看到预先打包的“框架桥”。NicholasC.Zakas对从应用程序中抽象出框架进行了很好的讨论。关于将框架与应用程序分离的重要性,这真的很好,也很深入


我相信您可能会发现的新版本(alpha版本)正是您正在寻找的类型

引用自述文件的第一行:

JavaScript框架共享类似的功能 特性和功能,例如 DOM操作、事件注册、, 和CSS选择器引擎。FuseJS 试图整合这些优势 将这些框架整合为一个稳定的, 高效、优化的核心 JavaScript框架


它也很漂亮,因为它的特点。(这也是一个独立的库!)我还没有机会使用它们(即基准测试和浏览器测试),但是这个概念非常漂亮。(基本上,它使用各种各样的技巧来提供一种扩展数组、对象等的方法,而不扩展这些对象的全局版本。有趣吗?

我不明白,你想要一个看起来像jQuery、闻起来像jQuery、甚至尝起来像jQuery的框架。。。为什么不直接使用jQuery…@Andrew-因为他不想依赖于框架。@Andrew-Chase很合适。我将把我现有的jQuery插件移植到vanilla javascript中,这样90%的代码都不会使用任何框架,因为不使用框架是不可行的,比如选择器和DOM操作(在vanilla js中这样做非常痛苦),少量代码应该使用不可知的框架适配器。选择以jQuery为主的接口是因为jQuery的巨大市场份额,因此是一个很好的采用决策。关于仅仅将我的插件移植到jQuery和MooTools版本,必须维护两个代码库是远远不够的。所以你想要一个框架,允许你的代码与框架无关吗?@Anurag heh,说得好+1。有些人仍然认为世界语是个好主意。。。顺便问一下,为什么要抛出错误并要求mootools具有sizzle?您应该看看1.3版推出的
slick
,它将与sizzle渲染的结果更加兼容。事实上,他们更顺从。句号。+1精彩的演讲,值得任何高级JavaScript程序员聆听!谢谢你的链接!虽然它与这个问题关系不大,但不幸的是,我不能接受它作为一个答案。再次感谢您的链接,这肯定会在将来改进我的代码。观看演讲的最后部分会提供一个替代答案,从而涵盖这个问题。我将等待大约一周,看看其他人会想出什么,但这是一个很好的候选人作为一个可接受的答案。谢谢。我没有看到FuseJS与桥接器/适配器概念的关系,对我来说,它就像是另一个框架,就像jQuery或MooTools一样。问题是通过使用桥接器,使您的插件能够以尽可能少的代码使用jQuery和MooTools。@balupton--抱歉;从您的问题和评论来看,您所寻找的似乎是可以让您使用jQuery、Mootools类、
Dojo.include
Dojo.require
系统中的选择器引擎,以及Prototype中的阵列扩展,这些都在一个包中。据我所知,FuseJS是唯一一个尝试做任何事情的人,哪怕是一点点。(当然,除非你把moo4q系统算在内——但这也不是你想要的,因为它的设计目的是让你利用两个(而不是任何一个)库的优势。)观看了@Chase建议的Zakas讲座(the by,+1的精彩讲座)——一个普遍可扩展的,应用程序无关框架,允许您实现一个看起来像Zakas演示应用程序的应用程序核心部分的系统在野外并不存在(至少,据我所知)。也许这是一个需要填补的空白?是的,不用担心。我对你的评论有+1:)。看起来确实有一个空白,不是吗?但我想他最终的目标是,为每个应用程序定制桥接器,这样您就可以拥有尽可能少的代码。但是,你也可以用一个普通的桥接器做同样的事情,然后选择你想要在你的定制构建中包含哪些函数——解决这个问题。非常有趣的东西。