Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JavaScript Beyond jQuery
Search
Evan Solomon
June 08, 2013
Technology
1
530
JavaScript Beyond jQuery
WordCamp Milwaukee
Evan Solomon
June 08, 2013
Tweet
Share
More Decks by Evan Solomon
See All by Evan Solomon
Demystifying the Black Box of WordPress Core
evansolomon
1
3.4k
WordCamp Las Vegas -- Make stuff that people want
evansolomon
2
2.9k
You Have No Idea What Your Users Want
evansolomon
1
520
You Don't Know People
evansolomon
2
850
Other Decks in Technology
See All in Technology
SREには開発組織全体で向き合う
koh_naga
0
410
Fashion×AI「似合う」を届けるためのWEARのAI戦略
zozotech
PRO
2
1.1k
AI時代のワークフロー設計〜Durable Functions / Step Functions / Strands Agents を添えて〜
yakumo
3
1.8k
AWSインフルエンサーへの道 / load of AWS Influencer
whisaiyo
0
190
MariaDB Connector/C のcaching_sha2_passwordプラグインの仕様について
boro1234
0
1k
ペアーズにおけるAIエージェント 基盤とText to SQLツールの紹介
hisamouna
2
1.3k
Database イノベーショントークを振り返る/reinvent-2025-database-innovation-talk-recap
emiki
0
250
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
9.9k
Identity Management for Agentic AI 解説
fujie
0
340
マイクロサービスへの5年間 ぶっちゃけ何をしてどうなったか
joker1007
17
7.4k
子育てで想像してなかった「見えないダメージ」 / Unforeseen "hidden burdens" of raising children.
pauli
2
310
AIエージェント開発と活用を加速するワークフロー自動生成への挑戦
shibuiwilliam
4
770
Featured
See All Featured
From π to Pie charts
rasagy
0
88
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
180
Amusing Abliteration
ianozsvald
0
64
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.4k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
14
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
72
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
23
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.2k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
850
My Coaching Mixtape
mlcsv
0
9
Transcript
JavaScript Beyond $(document).ready()
speakerdeck.com/ evansolomon/ javascript-beyond-jquery
var name = 'Evan Solomon', twitter = name .replace(/ /g,
'') .replace(/^/, '@') .toLowerCase();
JavaScript != jQuery
1.Scope 2.Functions 3.Context 4.Inheritance 5.Control Flow
1. Scope
Always use the var keyword in declarations
var place = 'Milwaukee'; console.log(place); // 'Milwaukee'
Variables are implicitly global
var place = 'Milwaukee'; place === window.place; // true place
=== this.place; // true
Variable access flows down
var place = 'Milwaukee'; function where() { return place; }
where(); // 'Milwaukee'
2. Functions
Functions are closures
function quiet() { var whisper = 'Boom!'; } console.log(whisper); //
Undefined
But don’t forget var
function noisy() { oops = 'Boom!'; } console.log(oops); // 'Boom!'
Functions can be anonymous
jQuery(function() { return 'Ready!'; });
jQuery(function($) { $('.header').hide(); }); // We can use the $
to access jQuery in WordPress
Functions can execute themselves
(function() { return 'See?'; })(); // 'See?'
3. Context
Everything is an object Well, almost everything
var talk = function() { console.log('Hello!'); }; talk instanceof Object
// true
'Evan'.length // 4
var people = [ 'Evan', 'Alison' ]; people.join(', '); //
'Evan, Alison'
The this keyword gives context
this === window; // true
var context = 'global'; (function() { return this.context; })(); //
'global'
var context = 'global', stuff = { context: 'object', show:
function() { return this.context; } }; stuff.show(); // object
var Thing = function() { this.context = 'instance'; this.show =
function() { return this.context; }; }; thing = new Thing; thing.show(); // instance
Context is tricky
var context = 'global', stuff = { context: 'object', show:
function() { return this.context; } }, ohnoes = stuff.show; ohnoes(); // global
Context is controllable
var context = 'the window', show = function() { return
this.context; }; show.call(); // 'the window' show.call({context:'anything'}); // 'anything'
Context can be bound
var that = {context: 'safe'}, show = function() { return
this.context; }, bound = function() { return show.apply(that); }; show(); // undefined bound(); // 'safe'
4. Inheritance
Inheritance comes from prototypes
var nums = [1, 2]; nums.slice === Array.prototype.slice // true
nums.slice === nums.constructor.prototype.slice // true nums.constructor === Array // true
String.prototype.canadianize = function() { return this + ', eh!'; };
'Hello'.canadianize(); // 'Hello, eh!'
var evan = new Person('Evan'), john = new Person('Alison'); Person.prototype.sayHi
= function() { return 'I am ' + this.name; }; evan.sayHi(); // 'I am Evan' john.sayHi(); // 'I am Alison'
5. Control Flow
JavaScript is often asynchronous
$content = wp_remote_get($url); // $content is ready to use
var content = $.get(url); // content is *not* the body
of the remote response
$.get(url, { success: function(content) { // Now you can use
content } });
$(document).ready(function() { // Now the DOM is loaded });
$(function() { // Now the DOM is loaded }); https://github.com/jquery/
jquery/blob/2.0.2/src/ core.js#L162-L166
$('.thing').on('click', function() { // Now the element has been clicked
});
var request = $.get(url); request.done(function(content) { // Now the content
is available });
Thanks
Underscore is a utility library
var wordcamps = [ {place: 'Milwauke', when: 'today'}, {place: 'San
Francisco', when: 'later'}, ]; _.pluck(wordcamps, 'when'); // ['today', 'later']
var people = [ 'Evan', 'John', 'Alison', 'John' ]; _.uniq(people);
// ['Evan', 'John', 'Alison']
var go = function() { return 'Be patient'; }, notYet
= _.after(2, go); notYet(); // Undefined notYet(); // 'Be patient'
Underscore has great docs underscorejs.org
CoffeeScript compiles to JavaScript
var notYet = _.after(2, function() { return 'Be patient'; }
); notYet(); // Undefined notYet(); // 'Be patient'
notYet = _.after 2, -> 'Be patient' notYet() // Undefined
notYet() // 'Be patient'
easyObject = key: 'val' more: 'No problem' var easyObject; easyObject
= { key: 'val', more: 'No problem' };
implicitReturns = -> 'This is fun' implicitReturns() // 'This is
fun'
coffeescript.org & codeschool.com
Node.js is JavaScript on the server
var fs = require('fs'); fs.readFile('./stuff.txt', function(err, data) { console.log(data.toString()); });
var http = require('http'), server = function (req, res) {
res.end('Hello World!\n'); }; http.createServer(server) .listen(8080);