• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
An Introduction to JavaScript: Week 5
 

An Introduction to JavaScript: Week 5

on

  • 208 views

 

Statistics

Views

Total Views
208
Views on SlideShare
208
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    An Introduction to JavaScript: Week 5 An Introduction to JavaScript: Week 5 Presentation Transcript

    • Introduction to JavaScript #5 @danielknell Wednesday, 23 October 13
    • http://artsn.co/js-tpl Wednesday, 23 October 13
    • Recap function counter(count) { if (count === undefined) { count = 1; } console.log(count); if (count < 10) { counter(count + 1); } } counter(); Wednesday, 23 October 13
    • Recap function fib(n) { if (n < 2) { return n; } return fib(n - 1) - fib(n - 2); } Wednesday, 23 October 13
    • Recap function greeter(greeting) { var count = 0 ; function greet(name) { count++; } } console.log(greeting + ' ' + name + '! (#' + count + ')'); return greet; hi = greeter('Hi'); hi('Bob'); // Hi Bob (#1) hi('Fred'); // Hi Fred (#2) count // undefined Wednesday, 23 October 13
    • Recap function Animal(name, sound) { this.name = name; this.sound = sound; } dog = new Animal('fido', 'woof!'); cat = new Animal('puss', 'meow!'); dog.name // fido cat.name // puss Wednesday, 23 October 13
    • Recap function Animal(name, sound) { this.name = name; this.sound = sound; } Animal.prototype.greet = function() { console.log(this.sound); } dog = new Animal('fido', 'woof!'); cat = new Animal('puss', 'meow!'); dog.greet(); cat.greet(); Wednesday, 23 October 13
    • Recap function Dog(name) { this.name = name; this.sound = 'woof!'; } Dog.prototype = new Animal(null, null); dog = new Dog('fido'); Wednesday, 23 October 13
    • Recap function Dog(name) { Animal.call(this, name, 'woof!'); } Dog.prototype = new Animal(null, null); Wednesday, 23 October 13
    • Refactoring Wednesday, 23 October 13
    • Refactoring var el; el = document.getElementById('foo'); el.style.color = 'red'; el = document.getElementById('bar'); el.style.color = 'red'; el = document.getElementById('baz'); el.style.color = 'red'; Wednesday, 23 October 13
    • Refactoring function makeRed(id) { var el = document.getElementById('foo'); el.style.color = 'red'; } makeRed('foo'); makeRed('bar'); makeRed('baz'); Wednesday, 23 October 13
    • Slide Puzzle Wednesday, 23 October 13
    • JSON { "name": "Daniel Knell" , "website": "http://danielknell.co.uk/" } Wednesday, 23 October 13
    • JSONP myCallback({ "name": "Daniel Knell" , "website": "http://danielknell.co.uk/" }) Wednesday, 23 October 13
    • JSONP <script> function myCallback(data) { console.log(data.name); console.log(data.website); } </script> <script src="http://api.example.com/user? callback=myCallback"></script> Wednesday, 23 October 13
    • Slide Puzzle Wednesday, 23 October 13
    • Thats All Folks email: contact@danielknell.co.uk twitter: @danielknell website: http://danielknell.co.uk/ Wednesday, 23 October 13