background preloader

ECMAScript 5 Strict Mode, JSON, and More

ECMAScript 5 Strict Mode, JSON, and More
Previously I analyzed ECMAScript 5’s Object and Property system. This is a huge new aspect of the language and deserved its special consideration. There are a number of other new features and APIs that need attention, as well. The largest of which are Strict Mode and native JSON support. Strict Mode Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. Since ECMAScript 5 is backwards-compatible with ECMAScript 3, all of the “features” that were in ECMAScript 3 that were “deprecated” are just disabled (or throw errors) in strict mode, instead. Strict mode helps out in a couple ways: It catches some common coding bloopers, throwing exceptions.It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object).It disables features that are confusing or poorly thought out. Most of the information about strict mode can be found in the ES5 specification [PDF] on page #235. Related:  ProgrammingJavascript / PatternsJavascript

Storing Objects in HTML5 localStorage jslibraryboilerplate by dciccale An easy boilerplate for rolling your own JavaScript Library like jQuery, Zepto, Prototype, etc. The code is written in CoffeeScript, TypeScript and pure JavaScript. Skip this if you want to use pure JavaScript version For compiling CoffeeScript or TypeScript you will need to install Node.js After installing Node.js you can compile the files throgh command-line Install CoffeeScript package: npm install -g coffee-script Compile file: coffee jslibraryboilerplate_coffee.coffee Install TypeScript package: npm install -g typescript tsc jslibraryboilerplate_class.ts Include the ´.js´ file in an html document and you are done! Use any valid CSS selector for getting elements from the document // all p elements$('p');// all elements with class 'test'$('.test');// checkboxes$('input[type="checkbox"]'); You can add any method you need to work with a JSLB DOM collection

Build “Rock, Paper, Scissors” in JS | Across Time I Paper Beats Rock i. The Game 1/9 Save and Submit ii. User Choice 2/9 var userChoice = prompt("Do you choose rock, paper or scissors?") iii. var userChoice = prompt("Do you choose rock, paper or scissors?") iv.Computer Choice: Part 2 4/9 var userChoice = prompt("Do you choose rock, paper or scissors?") II Compare Function i. var compare = function(choice1,choice2) { if (choice1 === choice2) { return "The result is a tie!" ii. var compare = function(choice1,choice2) { if (choice1 === choice2) { return "The result is a tie!" iii. var compare = function(choice1,choice2) { if (choice1 === choice2) { return "The result is a tie!" iv. var userChoice = prompt("Do you choose rock, paper or scissors?") v. Like this: Like Loading...

Zend Framework & MVC Introduction - Zend Framework Quick Start Zend Framework Zend Framework is an open source, object oriented web application framework for PHP 5. Zend Framework is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. Using these components, we will build a simple database-driven guest book application within minutes. Model-View-Controller So what exactly is this MVC pattern everyone keeps talking about, and why should you care? Note: More Information Let's break down the pattern and take a look at the individual pieces: Model - This is the part of your application that defines its basic functionality behind a set of abstractions.

Top Down Operator Precedence Douglas Crockford Introduction Vaughan Pratt presented "Top Down Operator Precedence" at the first annual Principles of Programming Languages Symposium in Boston in 1973. Oddly enough, such an obviously utopian approach to compiler construction is completely neglected today. Another explanation is that his technique is most effective when used in a dynamic, functional programming language. JavaScript The situation changes with the advent of JavaScript. JavaScript is also object-oriented. We don't have time in this short chapter to deal with the whole JavaScript language, and perhaps we wouldn't want to because the language is a mess. Functions as first class objects. We will take advantage of JavaScript's prototypal nature to make token objects that inherit from symbols. Symbol Table Every token, such as an operator or identifier, will inherit from a symbol. var symbol_table = {}; The original_symbol object is the prototype for all other symbols. Let's define a function that makes symbols.

Syntax Guidelines - JavaScript Fundamentals JavaScript ignores whitespace The two lines below process similarly since JavaScript ignores whitespace. The first one uses less byte space, while the second one is easier for humans to read. var person="Francis"; var person = "Francis" ; JavaScript is case-sensitive The two variables below are different due to the variation in uppercase and lowercase letters in the variable naming. var myname = "Joe"; var MyName = "David"; Naming variables and functions When creating variable and function names do not start them with a number. var 3rd_name = "Erica"; var name_3 = "Erica"; Code comments Comments are usually used for human reading only. <! Semicolon ends statements Even though JavaScript automatically terminates statements if we forget to, adding semicolon to terminate them is best practice. var player_1 = "Cindy"; null - empty value The literal value null is used to assign no initial value where JavaScript might expect one. Dot notation and bracket notation ( ) - grouping expressions

Model–view–controller Model–view–controller (MVC) is a software pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.[1][2] The central component, the model, consists of application data, business rules, logic and functions. A view can be any output representation of information, such as a chart or a diagram. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants. The third part, the controller, accepts input and converts it to commands for the model or view.[3] Component interactions[edit] A typical collaboration of the MVC components In addition to dividing the application into three kinds of components, the Model–view–controller (MVC) design defines the interactions between them.[4] Use in web applications[edit] History[edit] See also[edit]

closure-compiler - Closure Compiler Closure Compiler Closure Compiler is a JavaScript optimizing compiler. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. It is used in many of Google's JavaScript apps, including Gmail, Google Web Search, Google Maps, and Google Docs. Try it out! It's easy to try the compiler through our web application at Get the Compiler Download the compiler at or using Maven. The zip file contains a README with quick instructions to get you started. User Documentation You can read more about Closure Compiler at We also have a few low-key wiki pages at Developer Documentation You can browse the source at We accept patches :)

Related: