Javascript foundations: Function modules

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Javascript foundations: Function modules - Presentation Transcript

    1. function modules Learning Javascript foundations John Hunter Nov 2008 1
    2. Review - object module var radio = { volume: 0, frequency: 88.0, changeVolume: function (direction) { if (direction === 'up') this.volume += 1; else this.volume -= 1; }, changeTuner: function (direction) { if (direction === 'up') this.frequency += 4; else this.frequency -= 4; } }; 2
    3. Good OO languages should support encapsulation - objects should be able to keep some properties private. We cannot create private properties in Javascript objects. But there are ways to achieve the same effect. 3
    4. function something () { var secretTreasure = '$$$'; } var myTreasure = something(); console.log(myTreasure); >>> undefined how can we get the secretTreasure ? 4
    5. function functionName (arguments) { var localVariable; scope return returnValue; } arguments, local variables and return values are all in the function scope 5
    6. function something () { var secretTreasure = '$$$'; var notSoSecretTreasure = secretTreasure; return notSoSecretTreasure; } var myTreasure = something(); console.log(myTreasure); >>> $$$ we can get the secretTreasure ? 6
    7. function someFunction (arguments) { var localVariable; scope closeure return returnValue; } returned value has access to var result = someFunction(); the function scope - even when the function has completed! 7
    8. function something () { secretTreasure is private var secretTreasure = '$$$'; return { getTreasureLength: function () { returned object shares scope return secretTreasure.length; with local variables }, doubleTheTreasure: function () { secretTreasure += secretTreasure; } }; } var mine = something(); console.log(mine.getTreasureLength()); >>> 3 mine.doubleTheTreasure(); >>> 6 console.log(mine.getTreasureLength()); we can interact with private variables using public methods 8
    9. Review object properties are public function local variables are private function closures provide access to local variables after the function has executed functions can provide modules with private data 9
    10. Thanks 10
    SlideShare Zeitgeist 2009

    + John HunterJohn Hunter Nominate

    custom

    509 views, 1 favs, 0 embeds more stats

    This presentation forms part of a tutorial on learn more

    More info about this document

    CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

    Go to text version

    • Total Views 509
      • 509 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories