当我看到 这个问题时,我想如果可以编写 jQuery compiler 将会很有帮助.现在,编译器是指接收 jQuery 代码并输出最终执行的原始 javascript 代码的东西.
When I saw this question I thought it would be helpful if a jQuery compiler could be written. Now, by compiler, I mean something that takes in jQuery code and outputs raw javascript code that is ultimately executed.
这就是我对 jQuery 代码执行块的设想:
This is how I vision a block of jQuery code execution:
我知道这是一个非常简化的模型,它可能要复杂得多,但我认为复杂性降低到重复第 2 步和第 3 步,并调用不同的原始 js 函数,并且每个使用所有或部分参数/先前结果的时间.
I understand that this is a very simplified model and it could be much more complex, but I think the complexity is reduced to steps 2 and 3 being repeated with different raw js functions being called and each time fed with all or a subset of parameters / previous results.
如果我们订阅该模型,那么我们可能会想出一些方法来让 jQuery 函数执行双重任务:
If we subscribe to that model, then we might come up with methods to make the jQuery functions perform double-duty:
raw_function(passed_params)raw_function(passed_params)我是否做出了一些错误的假设,使这成为不可能?任何想法 Firebug 的探查器如何尝试获取函数名称?可以用在这里吗?
Am I making some wrong assumptions that would make this impossible? Any ideas how Firebug's profiler attempts to get function names? Could it be used here?
编辑
我的想法是制作一个输入/输出为的黑盒:
What I was thinking was making a black box with input / output as:
普通 jquery 代码 → [BB] → 如果你不使用库你会写的代码
谢谢大家!
我想你的意思是:如果你写
I think what you mean is: if you write
var myId = $("#myId")
它将被转换为
var myId = document.getElementById("myId")
我认为可能,但问题是,jQuery 函数返回 jQuery 对象,所以在上面的例子中,第一个 myId 将是一个 jQuery 对象 &第二个将是一个节点对象(我认为),它将影响编译后在代码中稍后需要使用它的其他功能.特别是如果他们被锁住了
I think its possible, but the problem is, jQuery functions return jQuery objects, so in the above example, the first myId will be a jQuery object & the second will be a node object(i think) which will affect other functions that needs to use it later in the code after compilation. Especially if they are chained
其次,您必须确保转换确实具有性能优势.但是,如果您了解所有这些并且可以相应地计划您的代码,我认为这是可能的
secondly you will have to be sure that the conversion actually has performance benefits. However if you are aware of all this and you can plan you code accordingly, i think it will be possible
这篇关于Jquery *编译器*可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XMLHttpRequest 的 getResponseHeader() 的限制?Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)