Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-06-2013, 03:59 PM
PM User |
#1
Regular Coder
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
IE8 : Javascript Filter Method Object does not support this property or method
Hi Guys,
I am trying to use filter method to get distinct selected element in an array in my code. but i have issue calling that in IE 8 browser. "Object does not support this property or method " .
Is there an equivalent method or a workaround ?
Thanks
02-06-2013, 04:11 PM
PM User |
#2
Regular Coder
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
Some people call it
shimming -
Code:
(function(){
var AP=Array.prototype, AP2={
every: function(fun, scope){
var T= this, len= T.length;
if(typeof fun== 'function'){
for(var i= 0; i < len; i++){
if(i in T){
if(fun.call(scope, T[i], i, T)== false) return false;
}
}
return true;
}
return false;
},
filter: function(fun, scope){
var T= this, A= [], i= 0, itm, L= T.length;
if(typeof fun== 'function'){
while(i< L){
if(i in T){
itm= T[i];
if(fun.call(scope, itm, i, T)) A[A.length]= itm;
}
++i;
}
}
return A;
},
forEach: function(fun, scope){
var T= this, L= T.length, i= 0;
if(typeof fun== 'function'){
while(i< L){
if(i in T){
fun.call(scope, T[i], i, T);
}
++i;
}
}
return T;
},
indexOf: function(what, i){
if(!i || typeof i!= 'number') i= 0;
var L= this.length;
while(i<L){
if(this[i]=== what) return i;
++i;
}
return -1;
},
lastIndexOf: function(what, i){
var L= this.length;
i= i || L-1;
if(isNaN(i) || i>= L) i= L-1;
if(i< 0) i += L;
while(i> -1){
if(this[i]=== what) return i;
--i;
}
return -1;
},
map: function(fun, scope){
var T= this, L= T.length, A= Array(L), i= 0;
if(typeof fun== 'function'){
while(i< L){
if(i in T){
A[i]= fun.call(scope, T[i], i, T);
}
++i;
}
return A;
}
},
reduce: function(fun, temp, scope){
var T= this, i= 0, len= T.length, temp;
if(typeof fun=== 'function'){
if(temp== undefined) temp= T[i++];
while(i < len){
if(i in T) temp= fun.call(scope, temp, T[i], i, T);
i++;
}
}
return temp;
},
reduceRight: function(fun, temp, scope){
var T= this.concat().reverse();
return T.reduce(fun, temp, scope);
},
some: function(fun, scope){
var T= this, L= T.length;
if(typeof fun== 'function'){
for(var i= 0; i < L; i++){
if(i in T && fun.call(scope, T[i], i, T)){
return true;
}
}
}
return false;
}
}
for(var p in AP2){
if(!AP[p]) AP[p]= AP2[p];
}
})();
Users who have thanked mrhoo for this post:
02-06-2013, 04:13 PM
PM User |
#3
Regular Coder
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
Hi mrhoo,
thanks for the quick reply. that code scares me..
all that code is for the filter method ?
thanks
02-06-2013, 04:29 PM
PM User |
#4
Regular Coder
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
Code:
if(!Array.prototype.filter){
Array.prototype.filter= function(fun, scope){
var T= this, A= [], i= 0, itm, L= T.length;
if(typeof fun== 'function'){
while(i<L){
if(i in T){
itm= T[i];
if(fun.call(scope, itm, i, T)) A[A.length]= itm;
}
++i;
}
}
return A;
}
}
My previous post included filter with the other Array methods IE does not support before version 9.
Last edited by mrhoo; 02-06-2013 at 04:31 PM ..
02-06-2013, 05:38 PM
PM User |
#5
Regular Coder
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
hi mrhoo,
but should this work now on IE8 as iam using that now..?
thanks
02-06-2013, 06:35 PM
PM User |
#6
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,459
Thanks: 0
Thanked 498 Times in 490 Posts
Quote:
Originally Posted by
korssane
but should this work now on IE8 as iam using that now..?
Just add the code mrhoo provided and IE8 will use that to do the filter while all other browsers will continue to use the built in code. The first line tests if the method already exists and only adds the method if it doesn't.
The Following 2 Users Say Thank You to felgall For This Useful Post:
02-06-2013, 07:09 PM
PM User |
#7
Regular Coder
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
Hi felgall,
Are you talking about the 1st piece of code or the 2nd one ?
thanks
02-06-2013, 09:37 PM
PM User |
#8
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,459
Thanks: 0
Thanked 498 Times in 490 Posts
Quote:
Originally Posted by
korssane
Hi felgall,
Are you talking about the 1st piece of code or the 2nd one ?
thanks
The first piece of code includes all of the new array methods that IE8 doesn't support until you add that code. The second piece of code is that part of the first piece of code that specifically adds filter()
02-07-2013, 12:48 AM
PM User |
#9
Regular Coder
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
thanks guys. It really helps. I will close this thread.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 11:29 PM .
Advertisement
Log in to turn off these ads.