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.
→
じげん公式
October 31, 2014
Programming
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JS/jQueryのはなし
じげん制作勉強会での資料です。
じげん公式
October 31, 2014
More Decks by じげん公式
See All by じげん公式
ディレクションについて〜制作フロー編〜
zigexn_official
0
330
Other Decks in Programming
See All in Programming
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
450
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
410
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
290
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7.2k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
The Language of Interfaces
destraynor
162
27k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
How STYLIGHT went responsive
nonsquared
100
6.3k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
Exploring anti-patterns in Rails
aemeredith
4
540
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Transcript
JS/jQueryͷͳ͠ @͛͡Μ੍࡞ษڧձʢ2014-05-23ʣ
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 → άϩʔόϧΦϒδΣΫτʢwindowʣ
·ͱΊ this ͳΜͯා͘ͳ͍ $('img').hide().on('load', function() { var $img = $(this);
// ←มʹೖͯ͠͏·͖͘߹͓͏ setTimeout(function() { $img.fadeIn(); }, 1000); });
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ