10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript 即時関数間の行き来

Posted at

ぐぐっても簡単な説明が出なかったのでメモです

Dog.jsと
Garden.jsを読み込んで
それぞれ即時関数でくくったけど
アクセスできなくて悩んだ

Dog.js
;(function(){
    // 犬Class
    var Dog = function(aName){
        this.name = aName;
    };
    Dog.prototype.run = function(){
        console.log(this.name + '' + '走ったぞ!!!');
    };
    // windowオブジェクトのプロパティにしてあげると
    window.Dog = Dog;
})();
Garden.js
;(function(){
    // こっちでポチ生成できる
    var pochi = new Dog('ポチ');
    pochi.run();
    // ポチが走ったぞ!!!
})();

庭でポチが走れました

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?