Taking JavaScript Seriously IS NOT THE WORST IDEA.

Slides:



Advertisements
Similar presentations
The JavaScript Programming Language
Advertisements

JavaScript: A Language of Many Contrasts
Intro to JavaScript. JavaScript History Client (generally browser-side) language invented at Netscape under the name LiveScript around 1995 Netscape wanted.
Web Application Development Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College.
JavaScript: JS301 Week 1: An Introduction to JavaScript.
The Web Warrior Guide to Web Design Technologies
I just met you, and 'this' is crazy, but here's my NaN, so call(me) maybe? JavaScript is so weird.
Julian on JavaScript: Objects Julian M Bucknall, CTO.
Advanced JS The World's Most Misunderstood Programming Language ) Douglas Crockford( Shimon Dahan
Introduction to the C# Programming Language for the VB Programmer.
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Kevin Reuter & Brian Guthrie.  Multi-paradigm  Prototype based objects  Dynamic, weak typing.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
JAVASCRIPT Introduction Kenny Lam. What is Javascript?  Client-side scripting language that can manipulate elements in the DOM  Event-driven language.
CSE 190M Extra Session #5 JavaScript scope and closures slides created by Marty Stepp
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
CMSC 330: Organization of Programming Languages Ruby Hash Tables (and other topics)
JavaScript JavaScript is a scripting language that is most commonly used to add client- side programming to a web page. Some of the things it is used for.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Web Application Development Muhammad Ali.  The Problem  Changing the Content of Page Dynamically  Efficient Utilization of Resources.
Introduction to JavaScript Gordon Tian
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript. Overview Introduction: JavaScript basics Expressions and types Expressions and types Arrays Arrays Objects and Associative Arrays Objects.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
1 Overview JavaScript (Recommended Reading : Programming the World Wide Web, 4 th Edition, Robert W. Sebesta, Chapters 4, 5 – available at Steely Library)
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
Martin Kruliš by Martin Kruliš (v1.0)1.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
Javascript. What is JavaScript? Scripting (interpreted) language designed for the web Beware: JavaScript is case sensitive.
CSE 341 Lecture 29 a JavaScript, the bad parts slides created by Marty Stepp see also: JavaScript: The Good Parts, by.
JavaScript Best Practices Learn How to Write Better Quality JavaScript Software University Technical Trainers SoftUni Team.
JavaScript: The First Parts Part Three Douglas Crockford Yahoo! Inc.
JavaScript scope and closures
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
JavaScript Katie Fowle November 15, History Brendan Eich at Netscape, 1995 Need for interactivity in web pages Mocha, LiveWire, LiveScript, then.
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Functions and Function Expressions Closures, Function Scope, Nested Functions, IIFE Software University Technical Trainers SoftUni Team.
Click to add Text Javascript Presented by Bunlong VAN Basic.
JavaScript: Good Practices
Chapter 4 Client-Side Programming: the JavaScript Language
JAVASCRIPT INTERVIEW QUESTIONS & ANSWERS.
Modern JavaScript Develop And Design
Dr. Charles W. Kann III JavaScript Objects Dr. Charles W. Kann III
Scope, Objects, Strings, Numbers
JavaScript an introduction.
Modern JavaScript Develop And Design
CS5220 Advanced Topics in Web Programming JavaScript Basics
Tutorial 4 JavaScript as OOP Li Xu
CS5220 Advanced Topics in Web Programming Node.js Basics
CS3220 Web and Internet Programming JavaScript Basics
JavaScript CS 4640 Programming Languages for Web Applications
CS 4722 Computer Graphics and Multimedia Spring 2018
CS3220 Web and Internet Programming JavaScript Basics
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Taking JavaScript Seriously IS NOT THE WORST IDEA

A Brief History of JavaScript Invented at Netscape in 1995 Has nothing to do with Java Standardized by ECMAScript Current version is 3 Version 5 is available, but not widely adopted

JavaScript Types Types are: Number, String, Boolean Object, Function, Array Types get automatically converted when needed Examples: '' == '0' // false 0 == '' // true 0 == '0‘// true false == 'false'// false false == '0'// true false == undefined // false false == null// false null == undefined// true ' \t\r\n ' == 0 // true

JavaScript Types typeof works in a bizarre way typeof([0, 1, 2]) === 'object' To avoid problems: Use === and !== Explicitly convert using parseInt() and toString()

JavaScript Variables Have function scope If you don’t declare them, they are implicitly global (This is awful) Global environment has a name ( window in the browser, global in nodejs) To avoid problems, always declare all variables at the top of the function.

JavaScript Objects Everything is an object Objects are collections of key/value pairs Create using object literal notation var obj = { att1: 1, 'att2': 556.8, 'some att': { thing: 'sing', 'other thing': true } };

Creating Objects var iterator = function (arr) { return { myArr: arr, index: 0, next: function() { this.index += 1; return this.myArr[index - 1]; }, hasNext: function() { return this.index < this.arr.length; } }; } var it = iterator(['apples', 'bananas']) it.next() // 'apples' it.hasNext() // true it.next() // 'bananas' it.hasNext() // false

JavaScript Inheritance The stuff of madness Prototyping Objects inherit from other objects object.prototype points to the ‘parent’ object

Handling Inheritance Every object has a prototype of object Adding something to object.prototype will add it to all objects in all scripts on the page When enumerating objects, always use for (var key in object){ if (object.hasOwnProperty(key)) { //Do some stuff }

JavaScript Functions Are also objects Can be defined anywhere Look like this: function name (arg1, arg2, arg3) { //Do some stuff } Used internally in the function

JavaScript Functions Can access the variables of their environment For example function outer(a, b) { var i, j; var inner = function() { //Can access a, b, i, j, inner } Closure of inner

Information Hiding with JS var iterator = function (arr) { var index = 0; return { next: function() { index += 1; return arr[index - 1]; }, hasNext: function() { return index < arr.length; } }; } var it = iterator(['apples', 'bananas']) it.next() // 'apples' it.hasNext() // true it.next() // 'bananas' it.hasNext() // false

Functions can be executed right after definition Use this to create a module that won’t affect the global namespace Immediate Execution (function() { var v1, v2; //Put your code here })()

Events in JavaScript Not built into the language Use anonymous functions: node.addEventListener('click', function(event) { //handle the event here }

Misc Tidbits If you want to do defaults: Always put semi-colons on the ends of lines Put "use strict" at the top of your module function The. notation and [] notation are interchangeable Never ever ever use eval function (arg1, arg2) { arg1 = arg1 || 5; arg2 = arg2 || {}; }

JS File Template (function() { "use strict"; document.addEventListener('DOMContentLoaded', function() { //Initialization stuff here }); // Other code here })()

References Crockford, Douglas. JavaScript: The Good Parts. O’Reilly Media Inc, Cambridge, MA Stefanov, Stoyan, JavaScript Patterns. O’Reilly Media Inc, Cambridge, MA

Resources jslint Mozilla Developer Network W3CSchools

Exercise Change the file javascript_exercise.js so that the object returned by create_calorie_counter has no public data (see slide on information hiding) The exercise and these slides are available at Note the hash!

Pitch Preferences Once you’ve spoken to all three TAs, fill out the form at