Ternar operator used to object-detection


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if (typeof ArrayUtilites == "undefined" || !ArrayUtilites) {
  2. var ArrayUtilites = {};
  3. }
  4.  
  5. ArrayUtilites.each = (Array.prototype.forEach) ?
  6. function (a, f, o) {
  7. Array.prototype.forEach.call(a, f, o || ArrayUtilites);
  8. return ArrayUtilites;
  9. } :
  10. function (a, f, o) {
  11. for (var i = 0, it; it = a[i]; i=i+1) {
  12. f.call(o || ArrayUtilites, it, i, a);
  13. }
  14. return ArrayUtilites;
  15. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.