26. ECMAScript 5
var Position = function(x,y){
this.x= x || 0;
this.y= y || 0;
};
Position.prototype.getDistance = function(position){
return Math.sqrt(Math.pow(position.x-this.x,2)+Math.pow(position.y-
this.y,2));
};
Position.prototype.toString = function(){
return ''+this.x+','+this.y+'';
};
27. var multiline_string = (function () {/*
Podle
mě
ten nejhorší
způsob :(
*/}).toString().match(/[^]*/*([^]*)*/}$/)[1];
var multiline_string = `V ES6
to jde
bez problémů!`;
var multiline_string = 'Takhle
d*****e
se musí psát
string na více
řádků.';
var multiline_string = 'Nebo' +
'takhle - s tímhle zápisem alespoň umí' +
'pracovat PHPStorm';
var multiline_string =
['Nebo',
'takhle',
].join('n')
String
35. Browser vs. Node
● window
● <script src="..."></script>
● HTTP klient
● JQuery, Angular
● global
● var module = require("...");
● HTTP server, klient
● Express
36. Express
Routing
var http = require("http");
http.createServer(function(request, response){
if(request.url=='/') {
response.writeHead(200);
response.end('GET request to the home');
}else
if(request.url=='/objects') {
response.writeHead(200);
response.end('GET request to the objects');
}else{
response.writeHead(404);
response.end('Not fount :( ');
}
}).listen(80);
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('GET request to the home');
});
app.get('/objects', function (req, res) {
res.send('GET request to the objects');
});
37. Jasmine
testování
describe('lineCollision', function() {
it('//', function () {
expect(T.Math.lineCollision(0,0,10,10,0,2,10,12)).toBe(false);
});
it('/|', function () {
expect(T.Math.lineCollision(0,0,10,10,100,0,100,10)).toBe(false);
});
it('X', function () {
expect(T.Math.lineCollision(0,0,10,10,0,2,2,0)).toBe(true);
});
it('L', function () {
expect(T.Math.lineCollision(0,0,10,10,10,10,10,0)).toBe(true);
});
it('T', function () {
expect(T.Math.lineCollision(0,0,10,0,10,10,10,-10)).toBe(true);
});
it('/', function () {
expect(T.Math.lineCollision(0,0,10,10,1,1,9,9)).toBe(true);
});
it('!', function () {
expect(T.Math.lineCollision(0,0,0,2,0,4,0,10)).toBe(false);
});
});
43. http://www.itnetwork.cz/software/sublime-
text
Sublime Text 3 napsal Jon Skinner. Jde o komerční editor napsaný v C++ a jehož
licence stojí kolem 1400 Kč. Editor si ale můžete vyzkoušet a to na neomezenou
dobu. Bez licence se však čas od času při ukládání ukáže dialogové okno, kde je
doporučena koupě licence….
Honza Bittner | ITNetwork.cz