SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
Oliver Zeigermann | http://zeigermann.eu
Schmerzfreies JavaScript für Java-
Entwickler
Donnerstag, 25. April 13
Umfrage zum Start
Wer glaubt das?
1. JavaScript ist eine schlechte Sprache
2. Es ist gut für meine Karriere, JavaScript zu
beherrschen
Donnerstag, 25. April 13
Themen
• Hello World
• Grundlagen JavaScript
• Aufklärung gängigerVorurteile
• Tools und Frameworks
• Diskussion
Donnerstag, 25. April 13
Hello World
Donnerstag, 25. April 13
Hello World #1
<!DOCTYPE html>
<html>
<head>
<script>
alert("Hello World");
</script>
</head>
<body></body>
</html>
Donnerstag, 25. April 13
Hello World #2
<!DOCTYPE html>
<html>
<body>
<div id="log"></div>
<script>
var element = document.
getElementById("log");
element.innerHTML =
"<h1>Hello World</h1>";
</script>
</body>
</html>
Donnerstag, 25. April 13
Hello World #3
node -e "console.log('Hello World');"
Donnerstag, 25. April 13
Hello World #4
Donnerstag, 25. April 13
Grundlagen
Donnerstag, 25. April 13
Sprach-Konzepte
• Alles (bis auf Primitive) ist ein Objekt
• Alle Objekte sind "mutable"
• Funktionen sind Bürger erster Klasse
• Sind Objekte
• Können Daten enthalten
• Machen Scopes und Closures
• ProtoypischeVererbung
Donnerstag, 25. April 13
Objekt
var map = {olli: 'Huhu', zweites$Feld: 1,
$: "Auch sowas geht!"};
map.$;
map["zweites$Feld"];
map.hund = "Ganz neu geht auch";
map.f = function() { return "Aha!" };
for (var entry in map) {
console.log(entry + ":" + map[entry]);
}
Donnerstag, 25. April 13
Arrays
var array = ["a", "b", "c"];
array[1] = 20;
array instanceof Object;
array.push(4);
array.splice(1, 2);
for (var entry in array) {
console.log(entry + ":" + array[entry]);
}
Donnerstag, 25. April 13
Funktionen
var f1 = function(p1, p2) {
return p1 + p2;
}
var result1 = f1(1,2);
result1 === 3;
function f2() {
console.log("Called!");
}
var result2 = f2();
result2 === undefined;
Donnerstag, 25. April 13
Scopes
(function () {
var achso = "Ich bin weg";
})();
console.log(achso); // ReferenceError
Donnerstag, 25. April 13
Vorurteile
Donnerstag, 25. April 13
Die gängigstenVorurteile
• JavaScript hat keine Typen
• In JavaScript kann man keine Klassen und keine
Vererbung ausdrücken
• Module und Kapselung sind nicht möglich
• Es ist sehr leicht, versehentlich globaleVariablen
zu erzeugen
• JavaScript nervt nur und hat keine coolen
Sprachfeatures
Donnerstag, 25. April 13
Vorurteil: JavaScript
hat keine Typen
Donnerstag, 25. April 13
Typen
typeof "String" === "string";
typeof 1 === "number";
typeof 1.0 === "number";
typeof true === "boolean";
typeof {} === "object";
typeof function() {} === "function";
Donnerstag, 25. April 13
Vorurteil: In JavaScript
kann man keine Klassen und
keineVererbung ausdrücken
Donnerstag, 25. April 13
Klassen: Gebrauch
var olli = new Person("Olli", 42);
olli instanceof Person;
olli.sayHello("Oma");
// => Olli says hello to Oma
Donnerstag, 25. April 13
Klassen: Definition
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.sayHello =
function(name) {
console.log(
this.name + " says hello to " +
name);
};
Donnerstag, 25. April 13
Vererbung
function Customer(id, name, age) {
// super constructor
Person.call(this, name, age);
this.id = id;
}
// extends
Customer.prototype =
Object.create(Person.prototype);
Customer.prototype.constructor = Customer;
Donnerstag, 25. April 13
Vorurteil: Module
und Kapselung sind
nicht möglich
Donnerstag, 25. April 13
Kapselung
var Module = {};
(function() {
function InternalStuff() {...}
function Person(name, age) {
// uses class InternalStuff
}
Module.Person = Person;
})();
var olli = new Module.Person("Olli", 42);
Module.InternalStuff === undefined;
Donnerstag, 25. April 13
Wie die Kapselung funktioniert: Closures
Closures frei nach Douglas Crockford
Eine innere Funktion hat immer Zugriff auf alle
Variablen und Parameter ihrer äußeren Funktion,
auch wenn diese äußere Funktion bereits beendet ist
Donnerstag, 25. April 13
Vorurteil: Es ist sehr
leicht, versehentlich globale
Variablen zu erzeugen
Donnerstag, 25. April 13
Strict Mode
"use strict";
(function (param) {
var value = 10;
// error: no accidental setting of
// global variable
vaule = value + param;
return value;
}());
Donnerstag, 25. April 13
Vorurteil: JavaScript
nervt nur und hat keine
coolen Sprachfeatures
Donnerstag, 25. April 13
Closures seit ES5 vs. Java8
var array = [1, 2, 3];
array.forEach(function(e){
console.log(e);
});
array.filter(function(e){
return e > 2;
});
array.map(function(e){
return e + 100;
});
Donnerstag, 25. April 13
MehrVorurteile
• Es gibt keinen Standard, jeder Browser
implementiert seinen eigenen Dialekt
• JavaScript ist langsam
• JavaScript ist wie CSS und HTML für
Designer, nicht für richtige Entwickler
Donnerstag, 25. April 13
Tools und Frameworks
Donnerstag, 25. April 13
Entwicklungsumgebungen
• WebStorm
• Chrome Dev-Tools
• vi / emacs / TextMate /Sublime Text / etc.
gehen natürlich auch
Donnerstag, 25. April 13
Live-Demo WebStorm
Donnerstag, 25. April 13
Frameworks
• jQuery
• Twitter Bootstrap
• Jasmine
• Ext JS
• AngularJS
• TodoMVC
Donnerstag, 25. April 13
• Standard-JavaScript-Bibliothek
• Fast überall zu finden
• Adressiert Probleme bei der
Programmierung des DOMs
• Flexible Trennung vonView und Logik
• Auch für Erweiterung klassischer
Webanwendungen
jQuery
Donnerstag, 25. April 13
jQuery
$(document).ready(function(){
$("a").click(function(event){
alert("Thanks for visiting!");
});
});
Donnerstag, 25. April 13
Testen mit Jasmine
describe("Calculator"
...
it("principle" ....
expect(principle).
toEqual(199990);
);
...
);
Donnerstag, 25. April 13
Twitter Bootstrap: Responsive Layout
<div class="container">
<div class="hero-unit">
<h1>Hello, world!</h1>
...
<a class="btn btn-
primary">Learn more &raquo;</a>
</div>
<div class="row">
<div class="span4">
<h2>Heading</h2>
...
Donnerstag, 25. April 13
Business-Anwendungen mit Ext JS
Donnerstag, 25. April 13
AngularJS
• Motto: HTML enhanced for web apps!
• Wie würde HTML aussehen, wenn es für
Anwendungen entwickelt worden wäre?
Donnerstag, 25. April 13
Hello World AngularJS
<!doctype html>
<html ng-app>
<head>
<script src="lib/angular.min.js">
</script>
</head>
<body>
<input ng-model="name">
<p>Hello {{name}}!</p>
</body>
</html>
Donnerstag, 25. April 13
TodoMVC
http://todomvc.com/
Donnerstag, 25. April 13
Bonus-Vorurteil
Donnerstag, 25. April 13
JavaScript ist nicht gut
geeignet für große,
langlebige Projekte
Donnerstag, 25. April 13
Hauptgrund: Fehlende
statische Typisierung
Donnerstag, 25. April 13
Live-Demo TypeScript
Donnerstag, 25. April 13
Zusammenfassung
• VieleVorurteile gegenüber JavaScript beruhen
auf Missverständnissen
• Strukturgebende Elemente (Klassen, Module)
sind in JavaScript über Patterns möglich
• JavaScript hat coole Sprachfeatures
• Es gibt mächtige Werkzeuge und Frameworks
• TypeScript erleichtert Entwicklung im großen
Stil
Donnerstag, 25. April 13
Umfrage zum Abschluss
Wer glaubt das nun?
1. JavaScript ist eine schlechte Sprache
2. Es ist gut für meine Karriere, JavaScript zu
beherrschen
Donnerstag, 25. April 13
Fragen / Diskussion
Oliver Zeigermann
http://zeigermann.eu
Donnerstag, 25. April 13

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Jax2013 JavaScript für Java-Entwickler