Created
August 2, 2013 05:12
-
-
Save shinofara/6137656 to your computer and use it in GitHub Desktop.
[JSを書く全ての人へ]複雑にナチがちなBackboneJSのモジュールをrequireJSで管理する入門 ref: http://qiita.com/shinofara/items/855a7345baa42ea69088
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|-- app.js | |
|-- index.html | |
|-- requires | |
| `-- test.js | |
`-- views | |
|-- test1.js | |
`-- test2.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hello RequireJS World!!! | |
index.htmlで最初から表 | |
testView1のrenderです。 | |
testView2のrenderです。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一番最初に実行されます。 test.js:1 | |
さて問題です、いつ処理が行われるしょう?実は二番目なんです(((〃ω〃)) test.js:13 | |
views/test1.jsが読み込まれました。 test1.js:1 | |
views/test2.jsが読み込まれました。 test2.js:1 | |
testView1のnewです。 test1.js:8 | |
testView1のrenderです。 test.js:7 | |
testView2のnewです。 test2.js:8 | |
testView2のrenderです。 test.js:8 | |
一番最後に実行されます。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 <!DOCTYPE html> | |
2 <html lang="ja"> | |
3 <head> | |
4 <meta charset="utf-8"> | |
5 <title>hello connect</title> | |
6 | |
7 <script src="//code.jquery.com/jquery-1.10.2.js"></script> | |
8 <script src="//underscorejs.org/underscore-min.js"></script> | |
9 <script src="//backbonejs.org/backbone-min.js"></script> | |
10 <script src="//requirejs.org/docs/release/2.1.8/minified/require.js"></script> | |
11 | |
12 </head> | |
13 <body id="body"> | |
14 hello RequireJS World!!! | |
15 | |
16 <div id='view'> | |
17 index.htmlで最初から表示<br/> | |
18 </div> | |
19 | |
20 <!-- #1 注目 --> | |
21 <script src="requires/test.js"></script> | |
22 </body> | |
23 </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 console.log('一番最初に実行されます。'); | |
2 | |
3 //依存モジュールを非同期ローディング | |
4 require(["views/test1", "views/test2"], function(test1, test2) { | |
5 | |
6 var testView1 = new test1.testView1(); | |
7 console.log(testView1.render()); | |
8 console.log((new test2.testView2()).render()); | |
9 | |
10 console.log('一番最後に実行されます。'); | |
11 | |
12 }); | |
13 console.log('さて問題です、いつ処理が行われるしょう?実は二番目なんです(((〃ω〃))') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 console.log('views/test1.jsが読み込まれました。'); | |
2 define(["//backbonejs.org/backbone-min.js"], function() { | |
3 var testView1 = Backbone.View.extend({ | |
4 el: 'body', | |
5 defaults: { | |
6 }, | |
7 initialize: function() { | |
8 console.log('testView1のnewです。'); | |
9 }, | |
10 render: function() { | |
11 $('#view').append('testView1のrenderです。<br/>'); | |
12 return 'testView1のrenderです。'; | |
13 } | |
14 }); | |
15 return { | |
16 testView1: testView1 | |
17 }; | |
18 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment