Jez*_*mas 3 javascript jquery magento prototypejs
我在Magento安装中有这个jQuery:
jQuery(document).ready(function($) {
"use strict";
var firstItems = $('.item.first');
// Find tallest .item per row; match rest of row to it
firstItems.each(function($) {
var $first, row, headings, heights, maxHeight;
$first = $(this);
row = $first.add($first.nextUntil(firstItems));
headings = row.find("h2, h5");
heights = headings.map(function($) {
return $(this).outerHeight();
});
maxHeight = Math.max.apply(null, heights);
headings.css("height", maxHeight);
});
});
Run Code Online (Sandbox Code Playgroud)
可悲的是,它与Prototype相冲突.它抛出错误:
[object object] is not a valid argument for 'Function.prototype.apply'
Run Code Online (Sandbox Code Playgroud)
这让我相信冲突来自第15行:
maxHeight = Math.max.apply(null, heights);
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以不同地包装该函数,以便它被原型忽略?
你是.applying一个jQuery对象,它应该是一个数组.
heights = headings.map(function($) {
return $(this).outerHeight();
}).toArray(); //<-- convert to array
Run Code Online (Sandbox Code Playgroud)
库没有添加原型Function.prototype.apply,它是一种原生方法.