1 if (jQuery && !jQuery.fn.forEach) {
2 $(function () {
3 (function ($) {
4 $.fn.extend({
5 forEach: function (predicate) {
6
7 if (this == null) {
8 throw new TypeError(' this is null or not defined');
9 }
10
11 // 1. Let O be the result of calling toObject() passing the
12 // |this| value as the argument.
13 var O = Object(this);
14
15 // 2. If isCallable(predicate) is false, throw a TypeError exception.
16 if (typeof predicate !== "function") {
17 throw new TypeError(predicate + ' is not a function');
18 }
19
20 //3 call the jq original API for iteror
21 $.each(O, function (index, domEle) {
22 predicate($(domEle));
23 });
24 }
25 })
26 })(jQuery);
27
28 });
29 }