Nodejs Array Some some(fun /*, thisp*/)

Here you can find the source of some(fun /*, thisp*/)

Method Source Code

/**//from w w w  .  j  a va  2  s.c o  m
 * Invokes `fun` on each element of the array and returns true if at least one
 * invocation of `fun` returns true or returns a truthy value.  Otherwise
 * returns false.
 *
 * The first argument given to `fun` is a single array element and the second
 * argument is the index of that element in the array.
 *
 * This definition is compatible with the JavaScript 1.6 definition for
 * `Array#every` in Spidermonkey.
 *
 * This implementation comes from:
 * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/some
 *
 * @function
 * @param   {Function}  fun     predicate function that will be applied to each
 * array element
 * @param   {Object}    [thisp] context in which `fun` will be invoked - `this`
 * in `fun` will refer to `thisp`
 * @returns {Boolean}   true if `fun` returned true for some array element, false otherwise
 */
Array.prototype.some = Array.prototype.some || function(fun /*, thisp*/) {
    var i = 0,
        len = this.length >>> 0;

    if (typeof fun != "function") {
        throw new TypeError();
    }

    var thisp = arguments[1];
    for (; i < len; i++) {
        if (i in this &&
            fun.call(thisp, this[i], i, this)) {
            return true;
        }
    }

    return false;
};

Related

  1. some(a,b)
    Array.prototype.some=function(a,b){
      "use strict";
      var c,d,e;
      if(void 0===this||null===this)
         throw new TypeError;
      if(e=Object(this),d=e.length>>>0,"function"!=typeof a)
        throw new TypeError;
      for(b=arguments.length>=2?arguments[1]:void 0,c=0;d>c;){
        if(c in e&&a.call(b,e[c],c,e))
    ...
    
  2. some(fn , context)
    Array.prototype.some = function(fn , context) {
      if (typeof fn != "function") {
        throw new TypeError(fn + " is not a function");
      if (typeof context === 'undefined') {
        context = this;
      for (var i = 0, l = this.length; i < l; i++) {
        if (this.hasOwnProperty(i) && fn.call(context, this[i], i, this)) {
    ...
    
  3. some(fun /*, thisArg */)
    Array.prototype.some = Array.prototype.some || function(fun ) {
        'use strict';
        if (this === void 0 || this === null)
            throw new TypeError();
        var t = Object(this);
        var len = t.length >>> 0;
        if (typeof fun !== 'function')
            throw new TypeError();
        var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
    ...
    
  4. some(fun /*, thisp*/)
    Array.prototype.some = function(fun ) {
        var len = this.length;
        if (typeof fun != "function") {
            throw new TypeError();
        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
        if (i in this && fun.call(thisp, this[i], i, this))
            return true;
    ...
    
  5. some(fun, thisArg)
    Array.prototype.some = function(fun, thisArg) {
      "use strict";
      var i, len, t;
      if (this === void 0 || this === null) {
        throw new TypeError();
      t = Object(this);
      len = t.length >>> 0;
      if (typeof fun !== "function") {
    ...
    
  6. some(iterator)
    Array.prototype.some = function(iterator) {
      for (var i = 0, len = this.length; i < len; i++) {
        if (iterator(this[i], i)) {
          return true;
      return false;
    };
    
  7. someArray.prototype.some || (fun /*, thisp */)
    Array.prototype.some = Array.prototype.some || function(fun ) {
      "use strict";
      if (this === void 0 || this === null) throw new TypeError();
      var t = Object(this);
      var len = t.length >>> 0;
      if (typeof fun !== "function") throw new TypeError();
      var thisp = arguments[1];
      for (var i = 0; i < len; i++) {
        if (i in t && fun.call(thisp, t[i], i, t)) return true;
    ...
    
  8. someMethod()
    Array.prototype.someMethod = function() {
        return 'this is just a test';
    };
    export {Array};