JavaScript Tips

837
-1

Published on

この本を読んだ一部のまとめ
http://www.amazon.co.jp/dp/4873113911

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
837
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • JavaScript Tips

    1. 1. JavaScript Good Parts
    2. 2. ••••
    3. 3. • function hoge () { }• var hoge = function () { };
    4. 4. • hoge(); // ‘hello’ function hoge () { return ‘hello’; }• hoge(); // TypeError: undefined is not a function var hoge = function () { return ‘hello’; };
    5. 5. • jQuery.get(‘api.php’, function(data) { alert(data); });• (function() { // some code })();
    6. 6. • JavaScript var f = function () { var hoge = ‘moge’; alert(hoge); // ‘moge’ }; alert(hoge); // undefined
    7. 7. • var hoge = ‘moge’; var f = function () { alert(hoge); // ‘moge’ };
    8. 8. • <script> var hoge = ‘moge’; alert(window.hoge); // ‘moge’ </script>
    9. 9. • <script> (function () { var hoge = ‘moge’; alert(hoge); // ‘moge’; })(); alert(window.hoge); // undefined </script>
    10. 10. var Bird = function (name) { this.name = name;};Bird.prototype = { nakigoe: ‘piyopiyo’, say: function () { return this.name + ‘: ‘ + this.nakigoe; }};
    11. 11. new var tori = new Bird(“tori”); tori.say(); // “tori: piyopiyo”
    12. 12. • tori nakigoe name bird.nakigoe = ‘pugyaaa’; bird.name = ‘hoge’; bird.say() // ‘hoge: pugyaaa’;• new var tori = Bird(hoge); // this window window.name; // “hoge”
    13. 13. var bird = function (name) { var pub = {}, nakigoe = ‘piyopiyo’; pub.say = function () { return name + ‘: ‘ + nakigoe; }; return pub;};
    14. 14. var tori = bird(‘tori’);tori.say(); // ‘tori: piyopiyo’;tori.name // undefinedtori.nakigoe // undefined
    15. 15. var suzume = function (name) { var pub = bird(name), nakigoe = ‘chun chun’; pub.chun = function () { return name + ‘: ‘ + nakigoe; }; return pub;};
    16. 16. var tarou = suzume(‘tarou’);tarou.say(); // ‘tarou: piyopiyo’;tarou.chun(); // ‘tarou: chun chun’;

    ×