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'
Slide 44
Slide 44 text
5.
Control Flow
Slide 45
Slide 45 text
JavaScript
is often
asynchronous
Slide 46
Slide 46 text
$content = wp_remote_get($url);
// $content is ready to use
Slide 47
Slide 47 text
var content = $.get(url);
// content is *not* the body of
the remote response
Slide 48
Slide 48 text
$.get(url, {
success: function(content) {
// Now you can use content
}
});
Slide 49
Slide 49 text
$(document).ready(function() {
// Now the DOM is loaded
});
Slide 50
Slide 50 text
$(function() {
// Now the DOM is loaded
});
https://github.com/jquery/
jquery/blob/2.0.2/src/
core.js#L162-L166
Slide 51
Slide 51 text
$('.thing').on('click', function() {
// Now the element has been clicked
});
Slide 52
Slide 52 text
var request = $.get(url);
request.done(function(content) {
// Now the content is available
});