私はGoogleコンパイラを使い始めたばかりで、いくつかの問題を抱えています。最初は私の前処理されたコードでは空の配列を後で作成される変数に設定していますが、コンパイルすると変数が完全に削除されるので、後で使用しようとすると未定義になります。Googleコンパイラが変数に空の配列を割り当てていませんか?
ここでは少し修正したコードを示します。私は以下のフラグを使用しています、コンパイラの設定について
/**
* Equal Heights
*
* @see https://css-tricks.com/equal-height-blocks-in-rows/
*/
goog.provide('EqualHeights');
(function($) {
// = Equalize columns on load and resize
equal_heights();
$(window).resize(function() {
equal_heights();
})
var currentTallest = 0;
var currentRowStart = 0;
var rowDivs = new Array();
function setConformingHeight(el, newHeight) {
// set the height to something new, but remember the original height in case things change
el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
el.height(newHeight);
}
function getOriginalHeight(el) {
// if the height has changed, send the originalHeight
return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
}
function equal_heights() {
// find the tallest DIV in the row, and set the heights of all of the DIVs to match it.
$('[data-equalizer-watch]').each(function() {
// "caching"
var $el = $(this);
var topPosition = $el.position().top;
if (currentRowStart != topPosition) {
// we just came to a new row. Set all the heights on the completed row
for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);
// set the variables for the new row
rowDivs.length = 0;
// empty the array
currentRowStart = topPosition;
currentTallest = getOriginalHeight($el);
rowDivs.push($el);
}
else {
// another div on the current row. Add it to the list and check if it's taller
rowDivs.push($el);
currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);
}
});
// do the last row
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
setConformingHeight(rowDivs[currentDiv], currentTallest);
}
}
})(jQuery);
:19行目はとてものでrowDivsは、ライン44上の未定義まで表示されて削除されてしまいます。私も高度な最適化の複雑化レベルを使用していないことに注意してください:
--closure_entry_point main.js
--externs node_modules/google-closure-compiler/contrib/externs/jquery-1.9.js
--language_in ECMASCRIPTS5
--warning_level: VERBOSE
私はおそらく何かを明らかに不足しているが、ちょうど右のトラックに取得したいのです。ありがとう。