Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JS/jQueryのはなし | リジョブ社内勉強会
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
madapaja
May 12, 2015
Programming
370
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JS/jQueryのはなし | リジョブ社内勉強会
madapaja
May 12, 2015
More Decks by madapaja
See All by madapaja
BEAR.Sunday のはなし - 第89回PHP勉強会@東京
madapaja
3
2.4k
Ray.Di-Ray.AopからみるPHP5.4+フレームワークBEAR.Sunday
madapaja
3
720
Ray.Di / Ray.Aop コトハジメ
madapaja
3
2.5k
Other Decks in Programming
See All in Programming
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
620
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
250
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
160
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
360
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
210
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
130
Inertia Rails: The One-Person Framework with React & Friends
skryukov
0
170
Seven New Principles of Software Engineering
yegor256
0
350
phperだってパンチカードでコーディングしたい
o0h
PRO
0
480
続・コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions-again
handlename
0
130
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
120
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
210
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
650
Navigating Team Friction
lara
192
16k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
440
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
310
Believing is Seeing
oripsolob
1
250
The untapped power of vector embeddings
frankvandijk
2
2k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
740
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
490
Transcript
JS/jQueryͷ @Ϧδϣϒࣾษڧձ 2015-5-12
JS/jQueryΛ ͍͜ͳͨ͢Ίʹ େͳ͜ͱΛ ͠·͢
ࠓ͓͢͠Δ͜ͱ • JavaScriptͷείʔϓͷ͜ͱ • JavaScriptͷ this ͷ͜ͱ • ·ͱΊ
είʔϓͱԿ͔ʁ
είʔϓͱ ม͕ఆ໊ٛͨ͠લͰ͑Δ ൣғͷ͜ͱ
είʔϓͱ JavaScriptͰେ͖͘ҎԼͷ2ͭʹ͚ΒΕΔ • άϩʔόϧείʔϓ Ͳ͔͜ΒͰࢀরͰ͖Δείʔϓ • ϩʔΧϧείʔϓ ಛఆͷൣғͰࢀরͰ͖Δείʔϓ ͔͜͜ΒɺมͷείʔϓΛݟ͍͖ͯ·͢ɻ
είʔϓ var greeting = 'Hello, '; function greet(name) { var
message = greeting + name; isGreeted = true; alert(message); } greet('World'); // ← ? console.log(message); // ← ? console.log(isGreeted); // ← ?
είʔϓ var greeting = 'Hello, '; function greet(name) { var
message = greeting + name; isGreeted = true; alert(message); } greet('World'); // ← 'Hello, World' ͱΞϥʔτ console.log(message); // ← ະఆٛΤϥʔ console.log(isGreeted); // ← true
άϩʔόϧมͱϩʔΧϧม var greeting = 'Hello, '; // ←άϩʔόϧม function
greet(name) { var message = greeting + name; // ←ϩʔΧϧม isGreeted = true; // ←άϩʔόϧม alert(message); }
ϩʔΧϧมΛ࡞Δʹ 1. function ͷதͰมએݴ͢Δ 2. var Λ༻͍ͯมએݴ͢Δ ͷ྆ํ͕ඞͣඞཁ
͏ҰݟͯΈΑ͏ var greeting = 'Hello, '; function greet(name) { //
← functionͷதͰ… var message = greeting + name; // ← var Λ༻͍ͯมએݴʂ isGreeted = true; alert(message); }
Α͘͏ςΫχοΫ ଈ࣌ؔͰғ͍είʔϓΛ࡞Δ (function(){ // ← functionͷதͰ… var hoge; // ←
var એݴ 㱺 ϩʔΧϧมʂ })();
Α͘͏ςΫχοΫ ͪΖΜjQueryΛͬͨҎԼͷΑ͏ͳॻ͖ํͰ OK $.ready(function(){ // ← functionͷதͰ… var hoge; //
← var એݴ 㱺 ϩʔΧϧมʂ }); $(function(){ // ← functionͷதͰ… var hoge; // ← var એݴ 㱺 ϩʔΧϧมʂ });
είʔϓͷޮՌ มͷিಥ͕ආ͚Δ ಉ͡ม໊͕͋ͬͯɺผͷείʔϓͰ͋Ε ผͷมͱͳΔͨΊɺؒҧͬͯ༻தͷมΛ ॻ͖͑ͯ͠·ͬͨΓͱ͍ͬͨࣄނΛ͍͗͢
άϩʔόϧมΘͳ͍!!! • άϩʔόϧม୭ͰಡΈॻ͖ग़དྷͪΌ͏Α • ͔͍ࣗͬͯ͠ͳ͍ͱࢥ͍ͬͯͨάϩʔόϧ ม ผͷਓͬͯΔ͔͠Εͳ͍
άϩʔόϧมΘͳ͍!!! • ͦͷάϩʔόϧมͰɺผͷεΫϦϓτͷڍಈ ʹӨڹ͢Δ͔ • ͦͷάϩʔόϧมɺผͷεΫϦϓτ͔Β ॻ͖͑ΒΕΔ͔ • ͦͷϖʔδʹ͍ΖΜͳਓ͕ॻ͍ͨJS͕ಡΈࠐ ·Ε͍ͯΔ
͔ͩΒ
άϩʔόϧม Θͳ͍!!!
μϝɻθολΠɻά ϩʔόϧมʂ
ʢͪΖΜάϩʔόϧมΛΘͳ͚ΕͳΒͳ ͍έʔε͋ΔͷͰɺͦͷ࣌༻๏ɾ༰ྔΛकͬ ͯ༻͠·͠ΐ͏ʣ
this ͱԿ͔ʁ
this ͱ • JavaScriptͰࣗಈతʹఆٛ͞ΕΔϚδοΫม • Ͳ͜Ͱ this Λ͏͔ʢ͘͠ݺͼग़͞Ε ํʣʹΑΓɺ ࢦ͢༰͕ҟͳΔ
jQuery Ͱͷ this ͷྫ $('a').on('click', function() { var link_to =
$(this).attr('href'); return window.confirm( link_to + 'Ҡಈ͠·͔͢ʁ' ) }); • ͜ͷ this ΫϦοΫ͞Εͨ a λάࣗΛࢦ͠ ͍ͯΔ
ؔͰͷ this 4ύλʔϯΛ͑ΕOK • ΦϒδΣΫτϝιουݺͼग़࣌͠ͷ this • ؔΛ new ͨ࣌͠ͷ
this • .call()ɺ.apply() .bind() ͷࡍͷ this • ͦΕҎ֎ͷ this
ΦϒδΣΫτϝιουݺͼग़ ࣌͠ͷ this var user = { name: 'ଠ', greet:
function() { alert('Hello, ' + this.name + '!'); } }; user.greet(); // 'Hello, ଠ!' ͱΞϥʔτ͞ΕΔ
ؔΛ new ͨ࣌͠ͷ this function User(name) { this.name = name;
} var user = new User('ଠ'); alert(user.name); // 'ଠ' ͱΞϥʔτ͞ΕΔ
.call()ɺ.apply() .bind() ͷࡍ ͷ this ͍͜͠ͷͰงғؾ͚ͩ var user =
{ name: 'ଠ', greet: function() { alert('Hello, ' + this.name + '!'); } }; user.greet.call({name: 'Ֆࢠ'}); // 'Hello, Ֆࢠ!' ͱΞϥʔτ͞ΕΔ user.greet.apply({name: 'Ֆࢠ'}); // 'Hello, Ֆࢠ!' ͱΞϥʔτ͞ΕΔ var userHanakoGreet = user.greet.bind({name: 'Ֆࢠ'}); userHanakoGreet(); // 'Hello, Ֆࢠ!' ͱΞϥʔτ͞ΕΔ
ͦΕҎ֎ͷ this function setOnClick() { this.onclick = function() { alert('Click͞Ε·ͨ͠!');
}; } setOnClick(); • ͜ͷ this άϩʔόϧΦϒδΣΫτΛࢦͯ͠ ͍Δ • ϒϥβͷάϩʔόϧΦϒδΣΫτ window ΦϒδΣΫτ • this.onclick window.onclick ͱಉ͡ҙຯ
͏ᘳͰ͢Ͷʁ
͜ͷ this Կʁ (function(){ this; // !ʁ });
͑ (function(){ this; // !window(άϩʔόϧΦϒδΣΫτ) });
͜ͷ this Կʁ var obj = { hoge: function() {
this; // !ʁ } }; obj.hoge();
͑ var obj = { hoge: function() { this; //
!obj } }; obj.hoge();
͜ͷ this Կʁ $("li").each(function() { this; // !ʁ });
͑ $("li").each(function() { this; // ! li ΦϒδΣΫτ }); jQueryͰͷ࣮Πϝʔδ
each: function(callback) { for (var i = 0; i < elements.length; i++) { callback.call(elements[i]); // ← } }
ظͨ͠ಈ࡞ʹͳΔʁ // ը૾͕ϩʔυ͞Εͯ $('img').hide().on('load', function() { // 1ඵޙʹϑΣʔυΠϯ setTimeout(function() {
$(this).fadeIn(); }, 1000); });
ظͨ͠ಈ࡞͠ ͳ͍ʂ
ͳͥʁ
͜ͷ߹ $('img').hide().on('load', function() { setTimeout(function() { $(this).fadeIn(); }, 1000); });
• ΦϒδΣΫτϝιουݺͼग़࣌͠ͷ this • ؔΛ new ͨ࣌͠ͷ this • .call()ɺ.apply() .bind() ͷࡍͷ this • ͦΕҎ֎ͷ this
෮श͠·͢ • ΦϒδΣΫτϝιουݺͼग़࣌͠ͷ this → ͦ ͷΦϒδΣΫτࣗ • ؔΛ new
ͨ࣌͠ͷ this → new͞ΕͨΦϒδ ΣΫτࣗ • .call()ɺ.apply() .bind() ͷࡍͷ this → ҾͰࢦఆͨ͠ΦϒδΣΫτ • ͦΕҎ֎ͷ this → άϩʔόϧΦϒδΣΫτ ʢwindowʣ
͜ͷ this window $('img').hide().on('load', function() { setTimeout(function() { $(this).fadeIn();
}, 1000); });
͜͏͢ΕOK $('img').hide().on('load', function() { var $img = $(this); // ←
มʹೖͯ͠ setTimeout(function() { $img.fadeIn(); // ← ͏ }, 1000); });
·ͱΊ
·ͱΊ ϩʔΧϧείʔϓେਓͷͩ͠ͳΈ 1. function ͷதͰ 2. varΛ༻͍ͯมએݴ͠Α͏ (function(){ var i_am_free
= 'ࣗݾදݱʂ'; })();
·ͱΊ this ͳΜͯා͘ͳ͍ • ΦϒδΣΫτϝιουݺͼग़࣌͠ͷ this → ͦ ͷΦϒδΣΫτࣗ •
ؔΛ new ͨ࣌͠ͷ this → new ͞ΕͨΦϒδ ΣΫτࣗ • .call()ɺ.apply() .bind() ͷࡍͷ this → ҾͰࢦఆͨ͠ΦϒδΣΫτ • ͦΕҎ֎ͷ this → άϩʔόϧΦϒδΣΫτ
·ͱΊ this ͳΜͯා͘ͳ͍ $('img').hide().on('load', function() { var $img = $(this);
// ←มʹೖͯ͠͏·͖͘߹͓͏ setTimeout(function() { $img.fadeIn(); }, 1000); });
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂ