»
AnglaisFrançaisVietnamien

Imprimer - Certaines fonctions JavaScript Prototype essentielles pour am?liorer vos applications JavaScript - JavaScriptBank.com

Version complète: jsB@nk » Snippet » Certaines fonctions JavaScript Prototype essentielles pour am?liorer vos applications JavaScript
URL: https://www.javascriptbank.com/some-essential-javascript-prototype-functions-to-enhance-your-javascript-applications.html

Certaines fonctions JavaScript Prototype essentielles pour am?liorer vos applications JavaScript © JavaScriptBank.comLe prototype fonctionne JavaScript dans ce tutorial JavaScript sont collect?s par ACC @ nk de nombreux Ressources JavaScript sur Internet Ces fonctions JavaScript prototype sont tr?s utiles et indispensables ? vos applications JavaScript , les applications Web si vous avez besoin pour r?duire le temps et de travail pour traiter T?ches JavaScript Et si vous n'?tes toujours pas bonne ? fonctions prototypes JavaScript , s'il vous pla?t lire l'article ci-dessous JavaScript :
? JavaScript Prototype : Quelques concepts de base
? Fonction Dollar Prototype
Codes source JavaScript de 13 fonctions JavaScript prototype pour traiter JavaScript Cordes, Les tableaux JavaScript Nombre et variables , s'il vous pla?t aller ? la page compl?te de la poste pour plus de d?tails , maintenant ACC @ nk vous montre quelques fonctions tr?s populaire prototype JavaScript seulement :
?

Version complète: jsB@nk » Snippet » Certaines fonctions JavaScript Prototype essentielles pour am?liorer vos applications JavaScript
URL: https://www.javascriptbank.com/some-essential-javascript-prototype-functions-to-enhance-your-javascript-applications.html



JavaScript
<script type="text/javascript">// -- Standard functions// String.contains() - See if a string contains a stringString.prototype.contains = function(str) {    return (this.indexOf(str) != -1);};// String.getChar() - Gets the character at a specific positionString.prototype.getChar = function(char_pos) {    return this.substring(char_pos, char_pos + 1);}// String.trim() - Strips spaces from beginning and end of stringString.prototype.trim = function() {    return this.replace(/^\s+|\s+$/g, '');};// Array.contains() - See if an array contains an objectif (typeof Array.prototype.contains === 'undefined') {    Array.prototype.contains = function(obj) {        var i = this.length;        while (i--) {            if (this[i] === obj) {                return true;            }        }        return false;    };}// Array.copy() - Copy an arrayif (typeof Array.prototype.copy === 'undefined') {    Array.prototype.copy = function() {        var a = [],            i = this.length;        while (i--) {            a[i] = typeof this[i].copy !== 'undefined' ? this[i].copy() : this[i];        }        return a;    };}// Array.forEach( function ) - Apply a function to each elementArray.prototype.forEach = function(f) {    var i = this.length,        j, l = this.length;    for (i = 0; i < l; i++) {        if ((j = this[i])) {            f(j);        }    }};// Array.indexOf( value, begin, strict ) - Return index of the first element that matches valueArray.prototype.indexOf = function(v, b, s) {    for (var i = +b || 0, l = this.length; i < l; i++) {        if (this[i] === v || s && this[i] == v) {            return i;        }    }    return -1;};// Array.insert( index, value ) - Insert value at index, without overwriting existing keysArray.prototype.insert = function(i, v) {    if (i >= 0) {        var a = this.slice(),            b = a.splice(i);        a[i] = v;        return a.concat(b);    }};// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches valueArray.prototype.lastIndexOf = function(v, b, s) {    b = +b || 0;    var i = this.length;    while (i-- > b) {        if (this[i] === v || s && this[i] == v) {            return i;        }    }    return -1;};// Array.random( range ) - Return a random element, optionally up to or from rangeArray.prototype.random = function(r) {    var i = 0,        l = this.length;    if (!r) {        r = this.length;    }    else if (r > 0) {        r = r % l;    }    else {        i = r;        r = l + r % l;    }    return this[Math.floor(r * Math.random() - i)];};// Array.shuffle( deep ) - Randomly interchange elementsArray.prototype.shuffle = function(b) {    var i = this.length,        j, t;    while (i) {        j = Math.floor((i--) * Math.random());        t = b && typeof this[i].shuffle !== 'undefined' ? this[i].shuffle() : this[i];        this[i] = this[j];        this[j] = t;    }    return this;};// Array.unique( strict ) - Remove duplicate valuesArray.prototype.unique = function(b) {    var a = [],        i, l = this.length;    for (i = 0; i < l; i++) {        if (a.indexOf(this[i], 0, b) < 0) {            a.push(this[i]);        }    }    return a;};// Array.walk() - Change each value according to a callback functionArray.prototype.walk = function(f) {    var a = [],        i = this.length;    while (i--) {        a.push(f(this[i]));    }    return a.reverse();};</script>