03_Javascript - UzanR/UzCodingNewLife GitHub Wiki
Filter an array (or array-like) object and return a filtered array containing only the item that satisfy a certain condition.
.grep(array, function, invert) + invert: true or false (true-return array which callback return false, false-return array which callback return true), default: false
$.grep([0,1,2], function(n,i){ return n > 0; }); //result 1, 2
var str = "purpose jiki system"; var pattr = new RegExp("p"); var res = pattr.test(str); // True
- Problem with the constructor function: Every object has its own instance of the function
- 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