JavaScript
Terminology
<dateObject>.getTime() ¶ Return the number of milliseconds from January 1st, 1970, to the time represented by the Date object.
<object>.hasOwnProperty(<property-name>) ¶ Returns true if <object> has a property of the specified name, false if it does not. This method does not check the properties in the object's prototype chain; the property must be a member of the object itself.
Object.keys(<object>) ¶ Returns an array of the given object's own enumerable properties.
parseInt(<string>) ¶ Attempt to parse a string as an integer.
<string>.match(<RegExp>) ¶ Matches a string with a regular expression, and returns an array containing the results of that search.
Facts, Thoughts and Opinions
Select random element from array (JavaScript)
value = myArray[Math.floor(Math.random() * myArray.length)];
Using $.extend() to "clone" a non-DOM object
// Define a first object and then use $.extend to create a merged object with a, b, and c
var ob1 = {a: 'hi', b: 'there'}
var ob2 = $.extend(ob1, {c: '!'});
// Modify ob2, but since the property doesn't exist except for ob1's prototype, it directly modifies ob1
ob2.a = 'There';
console.log(ob1);
----------------------------------------------------------------------------------------
// In order to "really" clone the non-DOM object, we need to do this
// Note the extra $.extend({}, ob1) that uses a blank object literal as the basis for the object
var ob1 = {a: 'hi', b: 'there'}
var ob2 = $.extend($.extend({}, ob1), {c: '!'});
ob2.a = 'There';
console.log(ob1);
Images
[[/div]]
- Subtopics
- JavaScript Arrays
- JavaScript Math
- JavaScript Objects
- JavaScript Strings
- JavaScript UI
- RegExp (JavaScript regular expression object)
Sources & Bookmarks