Skip to content

Instantly share code, notes, and snippets.

@1010real
1010real / page-index.js
Last active August 29, 2015 14:01
backbone note03
// 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();
@1010real
1010real / page-index.js
Created May 22, 2014 02:21
backbone note02
$(function(){
// Food Model
var Food = Backbone.Model.extend({
defaults: {
name:'',
calory:0
},
initialize: function() {
if (!this.get('name')) {
this.set("name", this.defaults.name);
@1010real
1010real / index.html
Last active August 29, 2015 14:01
backbone note01
<!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>
@1010real
1010real / page-index.js
Last active August 29, 2015 14:01
backbone note01
$(function(){
});
@1010real
1010real / addon.js
Created May 9, 2014 06:27
requireJS note01 addon.js - before
// addon.js
// 鍵カッコを定義
constant.startSquare = '「';
constant.endSquare = '」';
// 鍵カッコをつけた文字列を返す
function addSquareBracket(str) {
return getConstant('startSquare') + str + getConstant('endSquare');
}
@1010real
1010real / site-common.js
Created May 9, 2014 06:25
requireJS note01 site-common.js - before
// site-common.js
// サイト内で共通で使う定数を纏めたオブジェクト
var constant = {
title:'とあるサンプル',
description:'RequireJSをつかってみるとあるサンプル'
};
// 指定されたidに対する定数を返す関数
function getConstant(id) {
return constant[id];
@1010real
1010real / page.js
Created May 9, 2014 06:22
requireJS note01 page.js - before
// page.js
// ページロード時にタイトルと説明を表示
window.addEventListener('load', function(){
var title = addSquareBracket(getConstant('title'));
var description = getConstant('description');
commonPrint(title);
commonPrint(description);
});
@1010real
1010real / index.html
Last active August 29, 2015 14:01
requireJS note01 index.html - after
<!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>
@1010real
1010real / page.js
Last active August 29, 2015 14:01
requireJS note01 page.js - after
// 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);
//}); // 削除
});
@1010real
1010real / addon.js
Last active August 29, 2015 14:01
requireJS note01 addon.js - after
// addon.js
define(['site-common'], function(Common){
// 鍵カッコを定義
//constant.startSquare = '「'; // これはエラーに
//constant.endSquare = '」'; // これはエラーに
Common.setConstant('startSquare', '「'); //意図していた書き方に
Common.setConstant('endSquare', '」'); //意図していた書き方に
// 鍵カッコをつけた文字列を返す