Your SlideShare is downloading. ×
0
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Teaching old java script new tricks
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Teaching old java script new tricks

603

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
603
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Teaching Old JavaScript New Tricks
    Experiences building a server-side JavaScript framework
  • 2. Old JavaScript
    Over 15 years old
    Implemented everywhere:
    Browsers, Web Servers, Scripting, Phones
    Server Implementations (Old):
    Netscape, Rhino (JVM), Microsft IIS
    Old JavaScript feels “old”
    Namespacing, polluted globals, poor inheritance, not very modular..
    Those platforms don’t give you much
  • 3. New and Modern Tricks
    Modules, Namespacing
    “Separation of Concerns”
    Model, View, Controller (MVC):
    Request Routing (Controller)
    Object Relational Mapping (Model)
    Templating (Views)
    Binary, UTF-8, JSON, Callbacks
    Concise and Elegant
  • 4. Microsoft Javascript
    JScript on IIS (ASP)
    Not modern or cool, but old, stable and Windows hosting can be found everywhere
    JScript.dll updated with IE (up to 8) so it’s not ancient
    Not JScript.NET, not JIT, but quick enough (compared to other interpreters of it’s era)
  • 5. Why JS on the Server
    Code re-use, sure..
    Real strength: Heaps of stuff already written and tested:
    Parsers, Crypto, ORM, Testing, etc.
    (I’ve even seen a Linux Emulator)
    Expressive and Powerful:
    Callbacks/handlers, Query Iteration, flexible inheritance, extendibility (override built-in methods)
    Poor dates, formatting, etc. But easily fixed.
  • 6. The Framework
    Event Binding
    Bind to the “ready” event to attach controller code / route handlers
    Routes:
    Sinatra-style; named parameters
    Modules: load modules similar to common-JS
    Templating: compile your data in the route handler and then use template module to render your view
    Data Models: create your models, validation, methods and relationships
    Clean separation of code, helpful, intuitive interface
  • 7. Into the Code
    Hello World:
  • 8. Named Parameters
    Access to URL params
    Automatic JSON Output
  • 9. Using Libraries
    Similar to require() but uses lib()
  • 10. Application Structure
    /app
    /config
    /controllers
    /models
    /system
    /views
    /assets
    Public files (css, images, etc)
  • 11. Now the Cool Stuff
    ActiveRecord for JavaScript
    Powerful modeling, no writing SQL
    HTML Parser, DOM implementation and jQuery on the Server
    Read html files from file system and populate with dynamic content
    Webpage scraping with ease
    Node.js based dev-server
    Uses windows scripting host behind Node to use framework without
    Schema-less doc-store, Binary, Crypto, Advance language/full-text-search features, Persistent sessions with namespacing, etc.
  • 12. ActiveRecord
    Models are defined inside app/models
    Ported from Aptana’sActiveJS
  • 13. Model Validation and Relationships
    hasOne, hasMany, belongsTo
    validatesPresenceOf, validatesUniquenessOf, validatesLengthOf, etc
    Custom Validation functions and getter Methods
  • 14. Creating, Updating and Finding
    See Code
  • 15. jQuery Server Side DOM
    See Code
  • 16. Weaknesses and Future Development
    Needs better testing library (qunit)
    Debugging could be easier
    SQLite Adapter almost
    Working on adapters for other Server JS platforms (Apache + v8, Rhino on JVM)
    Good abstraction layers makes it not too closely coupled to current platform
  • 17. Wrapping Up
    What can be learned from Do It Yourself
    Not Re-inventing the Wheel
    Re-using other open-source code
    Github: http://github.com/sstur/aspjs

×