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 | |
//fc.create({name:'steaks', calory:400}); | |
//fc.create({name:'jelly', calory:50}); | |
// View of Food | |
var FoodView = Backbone.View.extend({ | |
tagName:'li', | |
className:'food', | |
initialize: function() { | |
this.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
$(function(){ | |
// Food Model | |
var Food = Backbone.Model.extend({ | |
defaults: { | |
name:'', | |
calory:0 | |
}, | |
initialize: function() { | |
if (!this.get('name')) { | |
this.set("name", this.defaults.name); |
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
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="js/lib/jquery.js"></script> | |
<script src="js/lib/underscore.js"></script> | |
<script src="js/lib/backbone.js"></script> | |
<script src="js/lib/backbone.localStorage.js"></script> | |
<script src="js/page-index.js"></script> | |
<title>deboo</title> |
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
$(function(){ | |
}); |
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
// addon.js | |
// 鍵カッコを定義 | |
constant.startSquare = '「'; | |
constant.endSquare = '」'; | |
// 鍵カッコをつけた文字列を返す | |
function addSquareBracket(str) { | |
return getConstant('startSquare') + str + getConstant('endSquare'); | |
} |
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
// site-common.js | |
// サイト内で共通で使う定数を纏めたオブジェクト | |
var constant = { | |
title:'とあるサンプル', | |
description:'RequireJSをつかってみるとあるサンプル' | |
}; | |
// 指定されたidに対する定数を返す関数 | |
function getConstant(id) { | |
return constant[id]; |
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
// page.js | |
// ページロード時にタイトルと説明を表示 | |
window.addEventListener('load', function(){ | |
var title = addSquareBracket(getConstant('title')); | |
var description = getConstant('description'); | |
commonPrint(title); | |
commonPrint(description); | |
}); |
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
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- require.jsの読み込みとメインファイルの指定 --> | |
<script src="require.js" data-main="page.js" async></script> | |
<title>test Document</title> | |
</head> | |
<body> |
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
// page.js | |
require(['site-common','addon'], function(Common, Addon){ | |
// ページロード時にタイトルと説明を表示 | |
//window.addEventListener('load', function(){ // 削除 | |
var title = Addon.addSquareBracket(Common.getConstant('title')); | |
var description = Common.getConstant('description'); | |
Common.commonPrint(title); | |
Common.commonPrint(description); | |
//}); // 削除 | |
}); |
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
// addon.js | |
define(['site-common'], function(Common){ | |
// 鍵カッコを定義 | |
//constant.startSquare = '「'; // これはエラーに | |
//constant.endSquare = '」'; // これはエラーに | |
Common.setConstant('startSquare', '「'); //意図していた書き方に | |
Common.setConstant('endSquare', '」'); //意図していた書き方に | |
// 鍵カッコをつけた文字列を返す |