Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

has.js

2,617 views

Published on

has.js presentation from AustinJS 16 Nov 2010

Published in: Technology
  • Be the first to comment

has.js

  1. 1. ' [f u‘‘'| ‘ 2; [ -: "|‘ ‘I I. _ II Ha I Qhlnkaiiuflc: : ’H. ~k‘lot-11|l_lI. | : .r'*urar- : ,I'}§_(5{lIl-”-
  2. 2. Me. >l< Dojo Toolkit Project Lead >l< J avaScript Engineer @joost / Adeonion >l< Blogs Infrequently : : http: / / higginsfo1_'president. net >l< Codes @CitHub 2: http: //github. com/ phiggins42 >l< Twitter: @phiggins >l< Beer Drinking Expert
  3. 3. THE DOJO FOUNDATION > Dojo Toolkit httpI/ /(lojofoundation. org ***‘k . _ ****
  4. 4. UA Sniffing >l< agreeably bad >24 easy to avoid mostly >l< sometimes impossible >l< or asynchronous. V - or unacceptable expense. v '45
  5. 5. in T75 ri I I I l‘ l I l: ;§i 'li-“on Ilia ta. -nuts __
  6. 6. Intent >l< Be Modernizr++! >l< https: //github. com/ Modernizr/ Modernizr >l< End Browser Sniffing
  7. 7. has. js, now >24 pure feature detection library >l< minimal api >l< minimal code size >l< consistent conventions >l< normalize names
  8. 8. prefab tests: (function(has, addtest, cssprop){ <> var tostring = {}. toString, NEW_DATE = new Date, FUNCTION_C ASS = "[object Function]"; / / Date tests addtest("date-toisostring", function(){ return tostring. ca11(NEW_DATE. toISOString) = = FUNCTION_CLASS; }); addtest("date-tojson", function(){ return tostring ca11(NEW_DATE. toJSON) = = FUNCTION_CLASS; }); addtest("date-now", function(){ return toString. ca11(Date. now) = = FUNCTION_CLASS; D; })(has, has. add, has. cssprop);
  9. 9. ‘ p - . _ , ,,, ,. ,-. 4)‘) . .l_. "I, C.. l C I3TJ. l,Ii3'.9I3l_l-=3C a u >1: Array = I= Function =1: Audio =1: Graphics = I= CSS =1=]SON * DOM = I= Video * Events >1: bugs, etc. = I= Form (html5y)
  10. 10. using has if(! has("date-tojson")){ Date. prototype. toJson = function(){ / * spec based supplemental shim */ } } my1ib. trim = has("string-trim") ? function(str){ return str. trim(); } : function(str){ / * regexp/ replace that guy */ };
  11. 11. exposed API has. addtest("my-funkytest", function(g, d, el){ / / g: Reference to global, typically ‘window‘ / / dz Refered to ‘document‘ element / / el: an element to use. // returns: Boolean; return true; }); has. addtest("my-othertest", function(){ return true; }, true); // immediately if(has("my-funkytest") && has("my-othertest")){ / * win. */ }
  12. 12. exposed API has. cssprop = function(name, el){ / / does this element support this css property } has. clearElement = function(el){ / / empty this element } has. isHostType = function(obj, prop){ / / check if the return type is different from the actual data type }
  13. 13. The plan >l< Collect Data. >l< Make a builder >24 and other tooling. >l< More tests. >l< Solve the async thing.
  14. 14. Collecting Data >l< Pre—populated test results var _testCache = g. globalexistingtestcache II {}; >l< Session Based Testing? >l< Browser Support Matrix >l< Platform Specific Builds >l< Mobile, Browser, Server
  15. 15. Collected Data >l< htt ): //dante. do'otoolkit. or _r/ has's/ tests/ runTests. html >l< http: / / f mbip. com/ hasjs (ads? )
  16. 16. Building >l< Closure Compiler Advanced Mode >l< Dead path removal‘? >24 http: / / code. google. com/ closure/ compiler/
  17. 17. Builder, step two. mylib. trim = has("string-trim") ? function(str){ return str. trim(); } : function(str){ / * regexp/ replace that guy */ }; // build = { “string-trim”: “true” } becomes: my. trim = true ? function(a){ return a. trim(); } : function(a){ / * . .. */ }; / / becomes: my. trim = function(a){ return a. trim(); }
  18. 18. Hopes and Dreams >34 Dojo 2.0, dojo—fd >24 Common st. andard codebase for libraries >Z< or personal consumption >l< CommonBrowser] S (#cbjs) >l< iiber. js — https: //github. com/ phiggins42/uber. js >l< es5shim? build option?
  19. 19. lj. a.s. .,j'C * https: //github. com/ phiggins42/has. js >I= http: //hasjs. org * #hasjs @ irc. freenode. net
  20. 20. ID THAI WC. _ I promise I’m done talking.
  21. 21. II. l_.3., .aga. i:1‘i_. . >14 http: //dantedojotoolkit. org >24 http: //higginsforpresident. net >14 http: //twitter. com/ phiggins >14 http: //github. com/ phiggins42 >24 phiggins @ irc. freenode. net

×