• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rubyslava2102
 

Rubyslava2102

on

  • 6,337 views

 

Statistics

Views

Total Views
6,337
Views on SlideShare
6,274
Embed Views
63

Actions

Likes
6
Downloads
85
Comments
1

7 Embeds 63

http://lanyrd.com 36
http://jorgejose4.wordpress.com 15
http://personajesjavi.blogspot.com 6
http://formacionmestreacasa.gva.es 2
http://vitalich.name 2
https://twitter.com 1
http://localhost 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rubyslava2102 Rubyslava2102 Presentation Transcript

    • JavaScript Márius ŠajgalíkRubyslava 21.2.2013 Márius Šajgalík 1
    • Ako vytvoriť objektvar o1 = { };var o2 = new Object();var o3 = { write: function(a) { console.log(a); } };o3.write(1);Rubyslava 21.2.2013 Márius Šajgalík 2
    • Ako vytvoriť objektfunction O4(){ this.write = function(a) { console.log(a); };}var O5 = function() { this.write = function(a) { console.log(a); };};var o4 = new O4();o4.write(1);Rubyslava 21.2.2013 Márius Šajgalík 3
    • Ako vytvoriť objektfunction Robot(_params) { var rotor; // private this.name; // public function init(params) { ... // compute _rotor from params rotor = _rotor; } init(_params);}Rubyslava 21.2.2013 Márius Šajgalík 4
    • Lokálne premennéfunction F1() { var x = 2; // poznáme iba vnútri F1 this.write = function() { console.log(x); };}var f1 = new F1();f1.write();f1.set = function(x2) { x = x2; }; // nové globálne xf1.set(3);f1.write(); // lokálne x nezmenenéconsole.log(x); // globálne x = 3Rubyslava 21.2.2013 Márius Šajgalík 5
    • thisfunction Robot(params){ var name = params.name; this.getName = function() { return name; }; this.getState = function() { ... return weather; }; this.hasUmbrella = function() { var state = ??? // this.getState is undefined };}Rubyslava 21.2.2013 Márius Šajgalík 6
    • thisfunction Robot(params){ ... var This = this; ... this.hasUmbrella = function() { var state = This.getState(); if (state.rain) return true; else return false; };}Rubyslava 21.2.2013 Márius Šajgalík 7
    • Ako zmeniť this?function predstavSa(meno) { console.log(Ahoj, som + this + a moje meno je + meno);}predstavSa.call(robot, Wall-E);predstavSa.apply(robot, [Wall-E]);Array.prototype.slice.call(Wall-E, 2, 5)Rubyslava 21.2.2013 Márius Šajgalík 8
    • Slovníkvar slovnik = { };slovnik[apple] = jablko;slovnik["oclock"] = hodín;slovnik[apple]; // jablkoslovnik[jablko]; // undefinedslovnik[constructor]; // functionRubyslava 21.2.2013 Márius Šajgalík 9
    • Slovníkfunction _slovnik() { var slovnik = { }; this.get = function(word) { if (word == constructor) word = _ + word; return slovnik[word]; }; this.set = function(word, translation) { if (word == constructor) word = _ + word; slovnik[word] = translation; };}var slovnik = new _slovnik();Rubyslava 21.2.2013 Márius Šajgalík 10
    • Slovníkfunction _slovnik() { var slovnik = { }; this.get = function(word) { return slovnik[_ + word]; }; this.set = function(word, translation) { slovnik[_ + word] = translation; };}var slovnik = new _slovnik();Rubyslava 21.2.2013 Márius Šajgalík 11
    • Ako spraviť asynchrónne APIvar API = { };API.xhr = { get: function(params, callback) { ... } getJSON: function(params, callback) { ... } post: function(params, callback) { ... }};Rubyslava 21.2.2013 Márius Šajgalík 12
    • Ako spraviť asynchrónne APIvar API = { };API._db = function (database) { function init(params, callback) { ... }; this.get = function(params, callback) { ... }; this.set = function(params, callback) { ... }; init({ db_name: database }, function(response) { if (response.error) console.error(response.cause); });};API.db = new API._db(my database);Rubyslava 21.2.2013 Márius Šajgalík 13
    • Ako spraviť asynchrónne APIget: function(params, callback) { DB.get(params.table, params.key, function(value) { callback({ ok: true, value: value }); }, function(error) { callback({ error: true, cause: error }); });}Rubyslava 21.2.2013 Márius Šajgalík 14
    • Ako spraviť asynchrónne APIvar API = { };API.core = { getKeywords: function(params, callback) { ... }};Rubyslava 21.2.2013 Márius Šajgalík 15
    • Variabilné parametregetKeywords: function(params, callback) { if (!params.URL) params = { URL: params }; if (!params.html) { API.xhr.get(params.URL,function(response) { params.html = response.html; This.getKeywords(params, callback); }); return; }}Rubyslava 21.2.2013 Márius Šajgalík 16
    • Variabilné parametregetKeywords: function(params, callback) { ... if (!params.words) { params.words = tokenize(params.html); } ...}Rubyslava 21.2.2013 Márius Šajgalík 17
    • Variabilné parametregetKeywords: function(params, callback) { if (params.words) { getKeywordsFromWords(params, callback); return; } if (params.html) { getKeywordsFromHtml(params, callback); return; } ...}Rubyslava 21.2.2013 Márius Šajgalík 18
    • Kopírovanie objektov – dedenieinštancií?var O = function () { this.write = function (a) { console.log(a); };};var o = new O();o.write(1);var p = Object.create(o);p.write(1);o.write2 = function (a) { console.log(a + 1); };o.write2(1);p.write2 = function (a) { console.log(a - 1); };o.write2(1);p.write2(1);Rubyslava 21.2.2013 Márius Šajgalík 19
    • Ako písať zátvorky?function areWeFinished(){ ...}function areWeFinished() { ...}Rubyslava 21.2.2013 Márius Šajgalík 20
    • Ako písať zátvorky?function areWeFinished(){ return { yes: true };}Rubyslava 21.2.2013 Márius Šajgalík 21
    • Ako písať zátvorky?function areWeFinished(){ return ; // takto to interpretuje JavaScript { yes: true };}areWeFinished(); // == undefined !!!Rubyslava 21.2.2013 Márius Šajgalík 22
    • Ako písať zátvorky?function areWeFinished() { return { yes: true };}Rubyslava 21.2.2013 Márius Šajgalík 23
    • areWeFinished() == trueRubyslava 21.2.2013 Márius Šajgalík 24