1

I just started a new job, and my first task is to clean up the Javascript code for the site - the problem is that there are two JS libraries being used (jQuery and Prototype / Scriptaculous).

I'm trying to figure out what's being used where, but it's pretty difficult, especially not being very familiar with the code.

Does anyone have any suggestions? I'd probably prefer to drop Prototype / Scriptaculous if possible.

4

5 に答える 5

2

これは横断的な変更になるため、javascriptライブラリを削除することはお勧めしません。非常に危険であり、現在および将来、偽のバグを引き起こす可能性があります。

于 2010-02-11T15:36:52.783 に答える
1

Prototypeが$変数を使用し、jQueryがnoConflictモードで実行されるため、jQuery変数によって参照される可能性があります。

たとえば、次のように注意が必要です。

 // here $ = Prototype

 jQuery(function($){
     // here $ = jQuery

 });

 // here $ = Prototype

そして別のファイルで:

// here $ = Prototype
(function($){
    // here $ = jQuery;
})(jQuery);
// here $ = Prototype

どのライブラリが参照されているかを確認するために、コンテキストに注意を払うことが非常に重要です。さらに、Prototypeで行われたjQueryで何かを行う方法に困惑した場合は、ここで質問することは完全に受け入れられます。

于 2010-02-11T15:38:22.593 に答える
0

特にPrototypeを取り除くことは、特にPrototypeを実際に「取得」したコードベースで作業している人々がいた場合、非常に邪悪になる可能性があります。私はここで自分自身について話していて、実際にはあなたが説明するミックスを正確に持っている非常に大きなWebアプリケーションに取り組んできました(ただし、Scriptaculousを離れる頃にはなくなっていたと思います)。

Prototypeの動作方法により、どこにでも依存関係が存在する可能性があります。

于 2010-02-11T15:39:02.653 に答える
0

This is a bit of a daunting task. The suggestion to live and let live both frameworks is not a bad one, provided things are working. It is likely jQuery is in noConflict mode if they are really resident on the same page.

One tool that's very useful is to use the Web Developer Toolbar for Firefox and navigate to a page and do: Information -> View JavaScript -- this will give you a full listing of all the JavaScript script loaded with <script> tags, as well as inline JavaScript in <script> tags, though I think inline event handlers are not listed there.

But one thing you can do is simply unhook Prototype or JavaScript and see which ends you up with fewer errors. Then you're on your way to debugging what's missing.

It is easier to standardize on one library, but there's a case to be made for "if it ain't broke, don't fix it" too.

I've taken some time to learn a bit about all frameworks, doing the same effects on identical HTML: ArtLung Rosetta: You can get a quick dive into the differences between syntaxes of Prototype and jQuery by comparing this and this.

Best of luck!

于 2010-02-12T21:36:17.407 に答える
0

I would trash prototype from all includes on all pages, remove the noconflict in jquery & then keep firebug ready to show me all errors, and go over all the pages one by one, replacing functions with jquery equivalents, until things work right.

..pain in the butt method, but doubt you'll find less painful. Might be helpful: http://api.jquery.com/browser/

于 2010-02-13T00:49:01.873 に答える