Ticket #2514: 2514_3.patch

File 2514_3.patch, 1.3 KB (added by Artur Formella, 15 years ago)
  • _source/core/tools.js

     
    299299         * @returns {Number} The (zero based) index of the first entry that matches
    300300         *              the entry, or -1 if not found.
    301301         * @example
    302          * var letters = [ 'a', 'b', 'c' ];
    303          * alert( CKEDITOR.tools.indexOf( letters, 'b' ) );  "1"
     302         * var letters = [ 'a', 'b', 0, 'c', false ];
     303         * alert( CKEDITOR.tools.indexOf( letters, '0' ) );  "-1" because 0 !== '0'
     304         * alert( CKEDITOR.tools.indexOf( letters, false ) );  "4" because 0 !== false
    304305         */
    305         indexOf : function( array, entry )
    306         {
    307                 for ( var i = 0, len = array.length ; i < len ; i++ )
    308                 {
    309                         if ( array[ i ] == entry )
    310                                 return i;
    311                 }
    312                 return -1;
    313         },
     306        indexOf :
     307                // #2514: We should try to use Array.indexOf if it does exist.
     308                // [].indexOf works everywhere if the the browser implementation is available.
     309                ( [].indexOf ) ?
     310                        function( array, entry )
     311                                {
     312                                        return index = array.indexOf( entry );
     313                                }
     314                :
     315                        function( array, entry )
     316                        {
     317                                for ( var i = 0, len = array.length ; i < len ; i++ )
     318                                {
     319                                        if ( array[ i ] === entry )
     320                                                return i;
     321                                }
     322                                return -1;
     323                        },
    314324
    315325        bind : function( func, obj )
    316326        {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy