Custom events allow data interchange between different modules or classes running in the current page.
These events are delivered as a broadcast. They are invoked with a "trigger" method, and catched with the "on" method.
Parameters are optional. If there are more than one, these have to be embedded in an array, yet the target methods must declare those parameters individually.
Thursday, March 10, 2016
Wednesday, October 28, 2015
Extracts a word which starts with a given substring
// extracts js_* class
$(anySelector).attr('class').match(/\bjs_[^\b]*?\b/)[0];
$(anySelector).attr('class').match(/\bjs_[^\b]*?\b/)[0];
Etiquetes de comentaris:
JavaScript,
jquery UI,
RegExp
Wednesday, June 17, 2015
Remove duplicates in an array
[1,1,2,2,3,3,4].reduce(function (a,b) { if (a.indexOf(b) < 0) a.push(b); return a;},[]);
will return [1,2,3,4]
In case of arrays composed of JSON objects use this expression for the "if"clause:
(JSON.stringify(a).indexOf(JSON.stringify(b))
Etiquetes de comentaris:
JavaScript
Subscribe to:
Posts (Atom)