Permalink
Browse files

Small 'ua' function optimisation. http://jsperf.com/tinycon-js-ua

  • Loading branch information...
1 parent ef308a3 commit 6258c8ebdfd99d554e4e0673a4142cf7082175f5 darren committed Feb 8, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 tinycon.js
View
@@ -24,11 +24,14 @@
fallback: true
};
- var ua = function(browser){
+ var ua = (function (browser) {
var agent = navigator.userAgent.toLowerCase();
- return agent.indexOf(browser) !== -1;
- };
-
+ // New function has access to 'agent' via closure
+ return function (browser) {
+ return agent.indexOf(browser) !== -1;
+ };
+ }());
+
var browser = {
chrome: ua('chrome'),
webkit: ua('chrome') || ua('safari'),

0 comments on commit 6258c8e

Please sign in to comment.