<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zip.the.code.unzip.the.life &#187; IE</title>
	<atom:link href="http://www.erolkabadayi.com/tag/ie/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erolkabadayi.com</link>
	<description>erol kabadayı</description>
	<lastBuildDate>Tue, 06 Apr 2010 01:30:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>IE&#8217;deki Array.indexOf problemi</title>
		<link>http://www.erolkabadayi.com/2008/07/18/134/</link>
		<comments>http://www.erolkabadayi.com/2008/07/18/134/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 10:48:44 +0000</pubDate>
		<dc:creator>Erol Kabadayı</dc:creator>
				<category><![CDATA[Yazılım]]></category>
		<category><![CDATA[Array.indexOf]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.erolkabadayi.com/?p=134</guid>
		<description><![CDATA[Javascript ile uğraşırken hepimiz mutlaka en az bir kere, bir dizinin içinde aradığımız bir değerin olup olmadığını kontrol etme ihtiyacı hissetmişizdir. Herkesin aklına ilk indexOf metodu gelir doğal olarak. Ama nedense diğer bir çok programlama dilinden aşina olduğumuz bu metod Internet Explorer takımının aklına gelmemiş. Firefox, opera ve safari tarafından desteklenen ve javascript motorlarına dahil [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript ile uğraşırken hepimiz mutlaka en az bir kere, bir dizinin içinde aradığımız bir değerin olup olmadığını kontrol etme ihtiyacı hissetmişizdir.</p>
<p>Herkesin aklına ilk indexOf metodu gelir doğal olarak. Ama nedense diğer bir çok programlama dilinden aşina olduğumuz bu metod Internet Explorer takımının aklına gelmemiş.</p>
<p>Firefox, opera ve safari tarafından desteklenen ve javascript motorlarına dahil etmiş oldukları indexOf methodu IE motoruna eklenmemiş ne yazık ki. Bu nedenle yazmış olduğunuz kod firefox, opera ve safari&#8217;de çalışırken IE&#8217;nin hiç bir sürümünde (IE7&#8242;de bile) çalışmayacak.</p>
<p>Ama korkmayın :-) Javascript burada da imdadımıza yetişiyor. Javascript&#8217;te bulunan temel Array sınıfını prototype ile genişleterek kodumuzun IE&#8217;de de sorunsuz çalışmasını sağlayabiliriz. Size iki alternatif kod aktaracağım. Herhangi birini kullanmakta serbestsiniz.</p>
<p>İlk önce Firefox&#8217;un kendi motorunda da kullanmış olduğu kodu görelim:</p>
<pre style="font-size: 11px;">if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from &lt; 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from &lt; 0)
      from += len;

    for (; from &lt; len; from++)
    {
      if (from in this &amp;&amp;
          this[from] === elt)
        return from;
    }
    return -1;
  };
}</pre>
<p>Veya aşağıdaki gibi daha basit bir kod kullanabiliriz:</p>
<pre style="font-size: 11px;">if(!Array.indexOf){

      Array.prototype.indexOf = function(s){
         for(var i = 0; i &lt; this.length; i++)
            if(this[i] === s) return i;

         return -1;
      }
   }</pre>
<p>Yukarıdaki kodlardan herhangi birini javascript kodunuza dahil ettiğinizde, kodunuz artık browser ayrımı yapmadan çalışacaktır.</p>
<pre style="font-size: 11px;">    var myArray = ["1","2","3","4"];
    alert(myArray.indexOf("3")); // Bütün browserler de 2 değerini verir.</pre>
<div><a style="color: #2244bb;" href="http://www.erolkabadayi.com/examples/IE_Array.indexOf.html" target="_blank">Örnek kod</a></div>
<div><span style="font-family: arial;"><span style="border-collapse: collapse; line-height: normal;">Önemli not : Her iki metod Firefox, IE, Safari ve Opera&#8217;da test edilmiş ve testi başarıyla geçmişlerdir.</span></span></div>
<div>Ayrıca inceleyin:</div>
<div><span style="font-family: arial;"><span style="border-collapse: collapse; line-height: normal;"></p>
<ul>
<li><a style="color: #2244bb;" href="http://www.hunlock.com/blogs/Mastering_Javascript_Arrays#quickIDX16" target="_blank">http://www.hunlock.com/blogs/Mastering_Javascript_Arrays#quickIDX16</a></li>
<li><a style="color: #2244bb;" href="http://www.erolkabadayi.com/blog/#%20http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:indexOf%20" target="_blank">http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:indexOf</a></li>
<li><a style="color: #2244bb;" href="http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/" target="_blank">http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/</a></li>
<li><a style="color: #2244bb;" href="http://snipplr.com/view/3355/arrayindexof/" target="_blank">http://snipplr.com/view/3355/arrayindexof/</a></li>
</ul>
<p></span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.erolkabadayi.com/2008/07/18/134/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->