03_Javascript - UzanR/UzCodingNewLife GitHub Wiki

grep

Filter an array (or array-like) object and return a filtered array containing only the item that satisfy a certain condition.

Syntax

.grep(array, function, invert) + invert: true or false (true-return array which callback return false, false-return array which callback return true), default: false

Example

    $.grep([0,1,2], function(n,i){
        return n > 0;
    });

    //result
    1, 2

RegExp

test()

    var str = "purpose jiki system";
    var pattr = new RegExp("p");
    var res = pattr.test(str);

    // True

Constructor/Prototype

  1. Problem with the constructor function: Every object has its own instance of the function
  2. Problem with the prototype: Modifying a property using one object reflects the other object also

=> Define all the object-specific properties inside the constructor and all shared properties and methods inside the prototype

⚠️ **GitHub.com Fallback** ⚠️