This document provides an overview of JavaScript for Java developers. It discusses the origins and history of JavaScript, including how it was influenced by Java syntax but developed separately. The document outlines similarities and differences between JavaScript and Java, as well as features of JavaScript like dynamic typing, prototypes, closures, and this keyword context. It recommends leveraging good JavaScript features like objects, functions, and JSON while avoiding bad patterns like direct DOM manipulation. Resources for further learning are also provided.
6. JavaScript Origins – LiveScriptJavaScript Origins – LiveScript
Interpreted scripting language
Simple enough for beginners
Dialect of Scheme
Self-inspired prototype model
HyperCard event model
Java syntax
Brendan Eich
7. JavaScript Origins – LiveScriptJavaScript Origins – LiveScript
Interpreted scripting language
Simple enough for beginners
Dialect of Scheme
Self-inspired prototype model
HyperCard event model
Java syntax
Brendan Eich
Implemented in 10 days
28. Java & JavaScript – What is SimilarJava & JavaScript – What is Similar
C-like syntax
Sandboxed
Java keywords are reserved in js
JS follows Java naming
conventions
29. Java & JavaScript – What is SimilarJava & JavaScript – What is Similar
C-like syntax
Sandboxed
Java keywords are reserved in js
JS follows Java naming
conventions
Make harder to see the
difference!
47. Objects as Hash TablesObjects as Hash Tables
function Person(name) {
this._name = name;
this.getName = function() {
return this._name;
};
}
var person = new Person("John");
person.age = 27;
person["city"] = "London"
48. Objects Literals, eval() and JSONObjects Literals, eval() and JSON
var myCar = {
color: "yellow",
wheels: 4,
engine: {
cylinders: 4,
size: 2.0
}
};
49. First Value FunctionsFirst Value Functions
var plus = function(x,y){ return x + y };
var minus = function(x,y){ return x - y };
var operations = {
'+': plus,
'-': minus
};
var calculate = function(x, y, operation){
return operations[operation](x, y);
}
calculate(38, 4, '+');
calculate(47, 3, '-');
51. PrototypesPrototypes
var Point = function(x) {
this.x = x;
return this;
};
Point.prototype = {
x: 0,
draw: function() { … }
};
p1 = new Point(10);
p2 = new Point(15);
52. this as function contextthis as function context
function bar() {
alert(this);
}
bar(); // global
var foo = {
baz: function() {
alert(this);
}
}
foo.baz(); // foo