Tech Tips

  1. Uncategorized
  2. 111 view

[Backbonjs][Javascript]Install

Install Backbone.js

Download needed libraries.
$wget http://code.jquery.com/jquery-1.10.1.min.js
$git clone https://github.com/documentcloud/underscore.git
$cp underscore/underscore-min.js .
$git clone https://github.com/douglascrockford/JSON-js.git
$cp JSON-js/json2.js .
$wget http://backbonejs.org/backbone-min.js
Next is making html and js for test.
<!DOCTYPE html>
<html>
<head>
  <title>Backbone Example</title>
</head>
<body>
  <h1>Backbone Example</h1>
  <script src="jquery-1.10.1.min.js"></script>
  <script src="json2.js"></script>
  <script src="underscore-min.js"></script>
  <script src="backbone-min.js"></script>
  <script src="js/app.js"></script>
</body>
</html>
(function() {
        console.log("Hello Backbone!");
}());
Try to access with browser.

Coffee Script

Please check here.
And install npm. Install libraries using package.json.
{
  "name": "sample",
  "version": "0.0.1",
  "dependencies": {
    "coffee-script": "*",
    "jasmine-node": "*",
    "grunt": "*"
  }
}
$npm install
Prepare Cakefile for building.
fs = require 'fs'
path = require 'path'
{spawn, exec} = require 'child_process'

coffee = (args) ->
  proc =         spawn './node_modules/.bin/coffee', args
  proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
  proc.on        'exit', (status) -> process.exit(1) if status != 0

jasmine = (args) ->
  proc =         spawn './node_modules/.bin/jasmine-node', args
  proc.stdout.on 'data', (buffer) -> console.log buffer.toString()
  proc.on        'exit', (status) -> process.exit(1) if status != 0

task 'build', "build source files in './src'  to './build'", ->
  target = [
    'src/main'
  ]
  coffee ['-j','tmp','-o','lib','-c'].concat target
  exec 'sleep 1 && cat build/tmp.js | grep -v "exports\." | grep -v "require(" > build/app.js', (err) ->
    throw err if err

task 'buildspec', "build source files in './spec' to './lib'", ->
  target = [
    'src/main'
    'spec/main_spec'
  ]
  coffee ['-j','tmpspec','-o','lib','-c'].concat target
  exec 'sleep 1 && cat build/tmpspec.js | grep -v "exports\." | grep -v "require(" > build/main_spec.js', (err) ->
    throw err if err

task 'clean', 'clean out temporary build files', ->
  if fs.readdirSync('lib/').length > 0
    exec 'rm js/*.js', (err) ->
      throw err if err

task 'spectest', 'run jasmine-node spec suite', ->
  invoke 'build'
  jasmine ['--coffee','--verbose','spec/']

task 'all', 'clean and build all', ->
  invoke 'clean'
  invoke 'build'
  invoke 'buildspec'

Preparing is over.
$vim src/app.coffee
obj = new Backbone.Model()

obj.set({name: "Murata"})
obj.set({age: 20})

console.log "obj: " + JSON.stringify(obj)
console.log "obj.name: " + obj.get("name")
$cake build
Try to access with browser. 参考ページ:http://appkitbox.com/knowledge/javascript/2013/03/15/backbone-1

Uncategorized recent post

  1. Run Amazon FreeRTOS on M5Stack Core2 for AWS …

  2. Udacity Self-Driving Car Engineer Nanodegree …

  3. Install sbt 1.0.0 and run sample template

  4. Visualization of Neural Network and its Train…

  5. [Machine Learning]Created docker image includ…

関連記事

PAGE TOP