This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function shuffle(){ | |
| var arr = arguments; | |
| var i = arr.length; | |
| while(i){ | |
| var j = Math.floor(Math.random()*i); | |
| var t = arr[--i]; | |
| arr[i] = arr[j]; | |
| arr[j] = t; | |
| }; | |
| return arr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isAppleDevice(){ | |
| var apple = {}; | |
| apple.ua = navigator.userAgent; | |
| apple.device = false; | |
| apple.types = ['iPhone', 'iPod', 'iPad']; | |
| for (var i = 0; i < apple.types.length; i += 1) { | |
| var t = apple.types[i]; | |
| apple[t] = !!apple.ua.match(new RegExp(t, "i")); | |
| apple.device = apple.device || apple[t]; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var style, css; | |
| if (document.createStyleSheet){ // IE | |
| style = document.createStyleSheet(); | |
| css = function(s){ | |
| style.cssText = s; | |
| } | |
| } else { | |
| style = document.createElement('style'); | |
| document.getElementsByTagName('head')[0].appendChild(style); | |
| css = function(s){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($){ | |
| $.widget("ui.mywidget", { | |
| options: { | |
| autoOpen: true | |
| }, | |
| _create: function(){ | |
| // by default, consider this thing closed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture | |
| (function(){ | |
| // code to be immediately invoked | |
| }()); // Crockford recommend this way | |
| (function(){ | |
| // code to be immediately invoked | |
| })(); // This is just as valid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var timer; | |
| window.addEventListener('resize', function(){ | |
| if(timer) return; | |
| /* ここに処理 */ | |
| timer = setTimeout(function(){ | |
| timer = undefined; | |
| }, 100); | |
| }, false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture | |
| var backetModule = (function(){ | |
| var basket = []; // private | |
| return { // exposed to public | |
| addItem : function(values){ | |
| basket.push(values); | |
| }, | |
| getItemCount : function(){ | |
| return basket.length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture | |
| function library(module){ | |
| $(function(){ | |
| if(module.init){ | |
| module.init(); | |
| }; | |
| }); | |
| return module; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture | |
| YAHOO.store.basket = function(){ | |
| var myPrivateVar = 'I can accessed only within YAHOO.store.basket.'; | |
| var myPrivateMethod = function(){ | |
| YAHOO.log('I can be accessed only from within YAHOO.store.basket.'); | |
| }; | |
| return { | |
| myPublicProperty : 'I am a public property.', | |
| myPublicMethod : function(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture | |
| var module = (function(){ | |
| var _private = { | |
| i : 5, | |
| get : function(){ | |
| console.log('current value:' + this.i); | |
| }, | |
| set : function(val){ | |
| this.i = val; |
OlderNewer