SlideShare une entreprise Scribd logo
1  sur  120
JavaScript
•
•
•
var name = "bender";

  var model = 22;
var name = ”Bender";

var name = ’Bender’;
var names = [”Bender", "Fry", "..."];
var theMagicObject = {
    "property1" : "value1",
    property2 : 123,
    property3 : function(){ return "yes"; }
};

theMagicObject.property1 // "value1"
theMagicObject.property2 // 123
theMagicObject.property3() // "yes"

theMagicObject["property1"] // "value1"
theMagicObject["property2"] // 123
theMagicObject["property3"]() // "yes"
==
!=        ++



+=
     --
true:
'1' == 1

 false:
'1' === 1
"2" - 1   // = 1

"2" + 1   // = 21
function bender(){
    ...
}

var bender = function(){
    ...
}
var name = function(){
    return "Bender";
}
alert(name);
var name = function(){
    return "Bender";
}
alert(name());
function log(a,b,c){
    // Stuff
}

log.length // 3
function(){
    // Jag är en annonym funktion
}
function loadProducts(category,callback){
     // Do some async work
     callback();
}

loadProducts("Robots",function(){
     // When the products are loaded
});
(function(){
    // Jag är en självanropande
    // anonym funktion
})();
var eat = function(food, beverage){
    ...
}

eat(”pizza”,”beer”) // OK!
eat(”pizza”); // OK! ("pizza", undefined)
eat(); // OK! (undefined, undefined)
var formatName = new Function(
     "firstName",
     "lastName",
     "company",
     "return lastName + ', ' + firstName
     + ' (' + company + ')'"
);

formatName("Anders","Jönsson","Avega");
// => Jönsson, Anders (Avega)
if
if(...){   for(...){
    ...        ...
}          }



if(...)    for(...)
{          {
    ...        ...
}          }
function isBender(model){
    return (model === "Bending Unit 22")
              ? "Yes!" : "Nooo!";
}
var items = {
    fry : function(){},
    bender : function(){},
    drZoidberg: function(){}
};

for(var item in items){
    console.log(item);
    // item()
    // items[item]()
}
var items = ["Fry","Bender"
                ,"Dr. Zoidberg"];

for(var item in items){
    console.log(item);
}

items.forEach(function(item){
    console.log(item);
});
var model = "Bender";

if(typeof robot === "undefined”){
    ...
}
undefined != "undefined"

var undefined = "hello";
var eat = function(food, beverage){
    if(food === undefined){
        // true
    }
}

eat();
var eat = function(food, beverage){
    if(typeof food === "undefined"){
         // true
    }
}

eat();
var eat = function(food, beverage){
    if(!food){
         // true
    }
}

eat();
var avega = {

     getOrgNumber: function(){
         ...
     },

     getAddress: function(){
         ...
     }

};

avega.getOrgNumber()
var avega = {};

avega.companyInfo = {

     getOrgNumber: function(){...}

};

avega.companyInfo.getOrgNumber()
namespace("avega.companyInfo", function(){

      // ...

});
// vad är this här?

avega = {
    getOrgNumber: function(){
         // vad är this här?
    }
};

avega.companyInfo = {
    getOrgNumber: function(){
         // vad är this här?
    }
};
String.prototype.trimDotts = function(){
    return this.replace(/./g,"");
}



var name = "..bender.";
name = name.trimDotts();
console.log(name); // bender
var Dictionary = function(){
    this._dictionary = {};
    this._count = 0;
};

Dictionary.prototype.count = function() {
    return this._count;
};

Dictionary.prototype.add = function(key, value) {
    if(this.get(key) === undefined){
        this._count++;
    }
    this._dictionary[key] = value;
};
...

var dic = new Dictionary();
var obj1 = function(){
    this.name = "obj1";
};

obj1.prototype.m1 = function(){
    console.log("m1 in " + this.name);
};

var obj2 = function(){               var x =   new obj2();
    this.name2 = "obj2";             x.m1();   // m1 in obj1
};                                   x.m2();   // m2 in obj2
obj2.prototype = new obj1();
                                     x.m3();   // m3 in obj1

obj2.prototype.m2 = function(){
    console.log("m2 in " + this.name2);
};

obj2.prototype.m3 = function(){
    console.log("m3 in " + this.name);
};
function save(){
    var robot = document.getElementById("robot");
    var status = document.getElementById("status");
    status.innerHTML = "Saving robot";

    saveAsync(robot, function(){
        status.innerHTML = "Robot saved";
    });
}

function saveAsync(robot, completeCallback){
    // Ajax save for robot
    completeCallback();
}

save();
function someFunction(){
    // här kommer vi åt x
    var y = 20;
}

var x = 10;
someFunction();
// här kommer vi inte åt y
function isBender(model){

    if(model === "Bending Unit 22"){
        var is = "Yes!";
    }else{
        var is = "Nooo!";
    }

    return is; // OK!
}
function fly(to){
     var color = "blue";
     if(to == "stockholm"){
           document.body.style.background = color;
           // ...
     }                                 Activation object
}                                 this            (global)
                                        arguments       ["stockholm"
fly("stockholm");                                       ]
                                        to              "stockholm"
                                        color           "blue"
  Execution context       Scope chain
 Scope chain          0
                      1                         Global object
                                        this            (global)
                                        document        (object)
                                        fly             function
                                        ...             ...
var handleSelection = function(){
    var numberOfSelected = 0;
    return {
        select: function(){
             numberOfSelected++;
        },
        deselect: function(){
             numberOfSelected--;
        },
        getNumberOfSelected: function(){
             return numberOfSelected;
        }
    };
}();

handleSelection.select();
handleSelection.select();
handleSelection.deselect();
// Vad returnerar följande: ?
handleSelection.getNumberOfSelected();
someMethod.call(this, arg1, arg2, ...)



                    .call()
                       &
                   .apply()


   someMethod.apply(this, args[])
var bender = {
    getFullName : function(){
        return "Bender Bending Rodríguez";
    },
    logFullName : function(){
        return "Bender's full name is: " + this.getFullName();
    }
};
var fry = {
    getFullName : function(){
        return "Philip J. Fry";
    },
    logFullName : function(){
        return "Fry's full name is: " + this.getFullName();
    }
};
bender.logFullName(); // Bender's full name is:    Bender Bending Rodríguez
fry.logFullName(); // Fry's full name is: Philip   J. Fry

fry.logFullName.call(bender);
// Fry's full name is: Bender Bending Rodríguez
•
•
•
•
•
function bender(){}
// ligger under window["bender"]

      var name = "bender"
// ligger under window["name"]
var fly = function(){
    // ...
}

fly();
window["fly"]();
<html>
<head>
     <title>Show all products</title>
     <link rel="stylesheet" href="products.css"
          type="text/css" media="all" />
</head>
<body>
     ...content...

     <script type="text/javascript"
          src="products-min.js"></script>
</body>
</html>
function timedProcessArray(items, process, callback){
     //create a clone of the original
     var todo = items.concat();

     setTimeout(function(){
          var start = +new Date();
          do {
                process(todo.shift());
          } while (todo.length > 0 &&
                (+new Date() - start < 50));
          if (todo.length > 0){
                setTimeout(arguments.callee, 25);
          } else {
                callback(items);
          }
     }, 25);
}
for(var i = 0; i < document.
     getElementsByTagName("input").length; i++){

     document
          .getElementsByTagName("input")[i]
          .style.visibility = "hidden";
}
var elements =
document.getElementsByTagName("input");

for(var i=0, length=elements.length; i<length; i++){
    var element = elements[i];
    element.style.color = "red";
    element.style.border = "solid 2px red";
    element.style.fontStyle = "italic";
}
var fragment =
document.createDocumentFragment();

                  *

          display: none;
•
•
http://nwipatriots.com/blog/wp-
content/uploads/2009/10/waiting-in-line.jpg
var http = require("http");

http.createServer(function (req, res) {

    res.writeHead(200, {
         "Content-Type" : "text/plain"
    });
    res.end("Hello Worldn");

}).listen(8124, "127.0.0.1");

console.log("Server running at
http://127.0.0.1:8124/");
Jag har inte copyright på bilderna, det har:
Vem vill bli miljonär - http://odetocode.com/Blogs/scott/archive/2009/03/18/signs-that-your-javascript-skills-need-updating.aspx
Gott och blandat http://webshop.gottelisa.se/ovrigt/gott-and-blandat.html
=== http://thelibeerian.blogspot.com/2010/11/people-cheat-say-it-aint-so.html
Funktioner http://perro.si/wp-content/uploads/2008/08/bb.gif
Enkät http://www.staffanstorp.se/images/18.3ba879f211de50c8d5580005605/enk%C3%A4tifyllande.jpg
Funktionsanrop http://ertos.nicta.com.au/research/l4.verified/visual.pml
Gråt http://1.bp.blogspot.com/_x7asENDXFm0/TKiGiVU1_RI/AAAAAAAAADQ/EPaYp_9L_Kg/s1600/dawson-crying.jpg
Closure citat http://jibbering.com/faq/notes/closures/
warning http://www.everestdigitalscanning.com/Everest_Website/Disaster_Services_files/warning_sign.jpg
Gråt http://www.ralphmag.org/EA/frenchman-crying500x368.gif
reflow http://www.wishfulthinking.co.uk/2006/04/24/creative-flow/
no shit sherlock http://images.retecool.com/uploads/BasTaart-NoShitSherlock.jpg
Finn x, http://www.princeton.edu/~hammett/puzzles/norway_math_test.html
Fry panic, http://tvlowcostquebec.wordpress.com/2008/06/23/advertisers-do-not-panic-in-tv-advertising-the-economic-approach-of-tvlowcost-allows-to-restore-the-%E2%80%9D-marketing-purchasing-power-%E2%80%9D-of-companies/
Stop, http://www.worldofstock.com/stock_photos/MES2105.php
Detour http://prayitoff.blogspot.com/2010/11/pray-it-off-111810-turning-speed-bumps.html
Comet http://www.newforestobservatory.com/wordpress/wp-content/gallery/quasarsandother/comet-lulin.jpg
V8 http://www.annonsera.se/stockholm-stockholm/fordon-b%C3%A5tdelar-_-tillbeh%C3%B6r/v8-marina-motorer-260-385-hk.html
First class http://blog.asiahotels.com/the-three-most-luxurious-airlines/singapore-airlines/
Telefoner http://www.ipadnytt.se/tag/javascript/
HTML http://www.techpin.com/cool-html-codes/
Important http://en.wikipedia.org/wiki/File:Nuvola_apps_important_blue.svg
Reflow http://code.google.com/intl/sv-SE/speed/articles/reflow.html
I have a dream http://bigdaddyseashell.wordpress.com/2008/04/04/early-morning-april-4/
Captain obvious http://bostonist.com/2005/05/28/tim_mccarver_still_sucks.php
Godis http://maidies.blogg.se/2010/may/godis.html

Contenu connexe

Tendances

Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoThe Software House
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptMichael Girouard
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!Brendan Eich
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Jung Kim
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Alexander Granin
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming heroThe Software House
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013aleks-f
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptecker
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax BasicsRichard Paul
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Bongwon Lee
 
Let the type system be your friend
Let the type system be your friendLet the type system be your friend
Let the type system be your friendThe Software House
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019corehard_by
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2Jeado Ko
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Kim Hunmin
 

Tendances (20)

Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScript
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
 
Sbaw091006
Sbaw091006Sbaw091006
Sbaw091006
 
Let the type system be your friend
Let the type system be your friendLet the type system be your friend
Let the type system be your friend
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5
 

En vedette

Java script의 이해
Java script의 이해Java script의 이해
Java script의 이해seungkyu park
 
Javascript入门到高阶
Javascript入门到高阶Javascript入门到高阶
Javascript入门到高阶ksky521
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionIn a Rocket
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanPost Planner
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldabaux singapore
 

En vedette (6)

Java script의 이해
Java script의 이해Java script의 이해
Java script의 이해
 
Javascript入门到高阶
Javascript入门到高阶Javascript入门到高阶
Javascript入门到高阶
 
Perio 4
Perio 4Perio 4
Perio 4
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 

Similaire à JavaScript - i och utanför webbläsaren (2010-03-03)

The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptkvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyHuiyi Yan
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oopLearningTech
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsColin DeCarlo
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboardsDenis Ristic
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Orlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't SuckOrlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't Suckerockendude
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 

Similaire à JavaScript - i och utanför webbläsaren (2010-03-03) (20)

The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
JavaScript patterns
JavaScript patternsJavaScript patterns
JavaScript patterns
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Orlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't SuckOrlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't Suck
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 

Dernier

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

JavaScript - i och utanför webbläsaren (2010-03-03)

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 17. var name = "bender"; var model = 22;
  • 18.
  • 19. var name = ”Bender"; var name = ’Bender’;
  • 20.
  • 21. var names = [”Bender", "Fry", "..."];
  • 22.
  • 23. var theMagicObject = { "property1" : "value1", property2 : 123, property3 : function(){ return "yes"; } }; theMagicObject.property1 // "value1" theMagicObject.property2 // 123 theMagicObject.property3() // "yes" theMagicObject["property1"] // "value1" theMagicObject["property2"] // 123 theMagicObject["property3"]() // "yes"
  • 24. == != ++ += --
  • 25.
  • 26. true: '1' == 1 false: '1' === 1
  • 27. "2" - 1 // = 1 "2" + 1 // = 21
  • 28.
  • 29.
  • 30. function bender(){ ... } var bender = function(){ ... }
  • 31. var name = function(){ return "Bender"; } alert(name);
  • 32. var name = function(){ return "Bender"; } alert(name());
  • 33. function log(a,b,c){ // Stuff } log.length // 3
  • 34. function(){ // Jag är en annonym funktion }
  • 35. function loadProducts(category,callback){ // Do some async work callback(); } loadProducts("Robots",function(){ // When the products are loaded });
  • 36. (function(){ // Jag är en självanropande // anonym funktion })();
  • 37.
  • 38. var eat = function(food, beverage){ ... } eat(”pizza”,”beer”) // OK! eat(”pizza”); // OK! ("pizza", undefined) eat(); // OK! (undefined, undefined)
  • 39.
  • 40. var formatName = new Function( "firstName", "lastName", "company", "return lastName + ', ' + firstName + ' (' + company + ')'" ); formatName("Anders","Jönsson","Avega"); // => Jönsson, Anders (Avega)
  • 41.
  • 42. if
  • 43. if(...){ for(...){ ... ... } } if(...) for(...) { { ... ... } }
  • 44. function isBender(model){ return (model === "Bending Unit 22") ? "Yes!" : "Nooo!"; }
  • 45.
  • 46. var items = { fry : function(){}, bender : function(){}, drZoidberg: function(){} }; for(var item in items){ console.log(item); // item() // items[item]() }
  • 47. var items = ["Fry","Bender" ,"Dr. Zoidberg"]; for(var item in items){ console.log(item); } items.forEach(function(item){ console.log(item); });
  • 48.
  • 49. var model = "Bender"; if(typeof robot === "undefined”){ ... }
  • 50. undefined != "undefined" var undefined = "hello";
  • 51. var eat = function(food, beverage){ if(food === undefined){ // true } } eat();
  • 52. var eat = function(food, beverage){ if(typeof food === "undefined"){ // true } } eat();
  • 53. var eat = function(food, beverage){ if(!food){ // true } } eat();
  • 54.
  • 55.
  • 56. var avega = { getOrgNumber: function(){ ... }, getAddress: function(){ ... } }; avega.getOrgNumber()
  • 57. var avega = {}; avega.companyInfo = { getOrgNumber: function(){...} }; avega.companyInfo.getOrgNumber()
  • 59.
  • 60. // vad är this här? avega = { getOrgNumber: function(){ // vad är this här? } }; avega.companyInfo = { getOrgNumber: function(){ // vad är this här? } };
  • 61.
  • 62. String.prototype.trimDotts = function(){ return this.replace(/./g,""); } var name = "..bender."; name = name.trimDotts(); console.log(name); // bender
  • 63. var Dictionary = function(){ this._dictionary = {}; this._count = 0; }; Dictionary.prototype.count = function() { return this._count; }; Dictionary.prototype.add = function(key, value) { if(this.get(key) === undefined){ this._count++; } this._dictionary[key] = value; }; ... var dic = new Dictionary();
  • 64.
  • 65.
  • 66. var obj1 = function(){ this.name = "obj1"; }; obj1.prototype.m1 = function(){ console.log("m1 in " + this.name); }; var obj2 = function(){ var x = new obj2(); this.name2 = "obj2"; x.m1(); // m1 in obj1 }; x.m2(); // m2 in obj2 obj2.prototype = new obj1(); x.m3(); // m3 in obj1 obj2.prototype.m2 = function(){ console.log("m2 in " + this.name2); }; obj2.prototype.m3 = function(){ console.log("m3 in " + this.name); };
  • 67.
  • 68.
  • 69.
  • 70. function save(){ var robot = document.getElementById("robot"); var status = document.getElementById("status"); status.innerHTML = "Saving robot"; saveAsync(robot, function(){ status.innerHTML = "Robot saved"; }); } function saveAsync(robot, completeCallback){ // Ajax save for robot completeCallback(); } save();
  • 71.
  • 72. function someFunction(){ // här kommer vi åt x var y = 20; } var x = 10; someFunction(); // här kommer vi inte åt y
  • 73. function isBender(model){ if(model === "Bending Unit 22"){ var is = "Yes!"; }else{ var is = "Nooo!"; } return is; // OK! }
  • 74.
  • 75. function fly(to){ var color = "blue"; if(to == "stockholm"){ document.body.style.background = color; // ... } Activation object } this (global) arguments ["stockholm" fly("stockholm"); ] to "stockholm" color "blue" Execution context Scope chain Scope chain 0 1 Global object this (global) document (object) fly function ... ...
  • 76.
  • 77.
  • 78. var handleSelection = function(){ var numberOfSelected = 0; return { select: function(){ numberOfSelected++; }, deselect: function(){ numberOfSelected--; }, getNumberOfSelected: function(){ return numberOfSelected; } }; }(); handleSelection.select(); handleSelection.select(); handleSelection.deselect(); // Vad returnerar följande: ? handleSelection.getNumberOfSelected();
  • 79.
  • 80. someMethod.call(this, arg1, arg2, ...) .call() & .apply() someMethod.apply(this, args[])
  • 81. var bender = { getFullName : function(){ return "Bender Bending Rodríguez"; }, logFullName : function(){ return "Bender's full name is: " + this.getFullName(); } }; var fry = { getFullName : function(){ return "Philip J. Fry"; }, logFullName : function(){ return "Fry's full name is: " + this.getFullName(); } }; bender.logFullName(); // Bender's full name is: Bender Bending Rodríguez fry.logFullName(); // Fry's full name is: Philip J. Fry fry.logFullName.call(bender); // Fry's full name is: Bender Bending Rodríguez
  • 83.
  • 84. function bender(){} // ligger under window["bender"] var name = "bender" // ligger under window["name"]
  • 85. var fly = function(){ // ... } fly(); window["fly"]();
  • 86.
  • 87. <html> <head> <title>Show all products</title> <link rel="stylesheet" href="products.css" type="text/css" media="all" /> </head> <body> ...content... <script type="text/javascript" src="products-min.js"></script> </body> </html>
  • 88.
  • 89.
  • 90. function timedProcessArray(items, process, callback){ //create a clone of the original var todo = items.concat(); setTimeout(function(){ var start = +new Date(); do { process(todo.shift()); } while (todo.length > 0 && (+new Date() - start < 50)); if (todo.length > 0){ setTimeout(arguments.callee, 25); } else { callback(items); } }, 25); }
  • 91.
  • 92. for(var i = 0; i < document. getElementsByTagName("input").length; i++){ document .getElementsByTagName("input")[i] .style.visibility = "hidden"; }
  • 93.
  • 94. var elements = document.getElementsByTagName("input"); for(var i=0, length=elements.length; i<length; i++){ var element = elements[i]; element.style.color = "red"; element.style.border = "solid 2px red"; element.style.fontStyle = "italic"; }
  • 95.
  • 98.
  • 99.
  • 100.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107. var http = require("http"); http.createServer(function (req, res) { res.writeHead(200, { "Content-Type" : "text/plain" }); res.end("Hello Worldn"); }).listen(8124, "127.0.0.1"); console.log("Server running at http://127.0.0.1:8124/");
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120. Jag har inte copyright på bilderna, det har: Vem vill bli miljonär - http://odetocode.com/Blogs/scott/archive/2009/03/18/signs-that-your-javascript-skills-need-updating.aspx Gott och blandat http://webshop.gottelisa.se/ovrigt/gott-and-blandat.html === http://thelibeerian.blogspot.com/2010/11/people-cheat-say-it-aint-so.html Funktioner http://perro.si/wp-content/uploads/2008/08/bb.gif Enkät http://www.staffanstorp.se/images/18.3ba879f211de50c8d5580005605/enk%C3%A4tifyllande.jpg Funktionsanrop http://ertos.nicta.com.au/research/l4.verified/visual.pml Gråt http://1.bp.blogspot.com/_x7asENDXFm0/TKiGiVU1_RI/AAAAAAAAADQ/EPaYp_9L_Kg/s1600/dawson-crying.jpg Closure citat http://jibbering.com/faq/notes/closures/ warning http://www.everestdigitalscanning.com/Everest_Website/Disaster_Services_files/warning_sign.jpg Gråt http://www.ralphmag.org/EA/frenchman-crying500x368.gif reflow http://www.wishfulthinking.co.uk/2006/04/24/creative-flow/ no shit sherlock http://images.retecool.com/uploads/BasTaart-NoShitSherlock.jpg Finn x, http://www.princeton.edu/~hammett/puzzles/norway_math_test.html Fry panic, http://tvlowcostquebec.wordpress.com/2008/06/23/advertisers-do-not-panic-in-tv-advertising-the-economic-approach-of-tvlowcost-allows-to-restore-the-%E2%80%9D-marketing-purchasing-power-%E2%80%9D-of-companies/ Stop, http://www.worldofstock.com/stock_photos/MES2105.php Detour http://prayitoff.blogspot.com/2010/11/pray-it-off-111810-turning-speed-bumps.html Comet http://www.newforestobservatory.com/wordpress/wp-content/gallery/quasarsandother/comet-lulin.jpg V8 http://www.annonsera.se/stockholm-stockholm/fordon-b%C3%A5tdelar-_-tillbeh%C3%B6r/v8-marina-motorer-260-385-hk.html First class http://blog.asiahotels.com/the-three-most-luxurious-airlines/singapore-airlines/ Telefoner http://www.ipadnytt.se/tag/javascript/ HTML http://www.techpin.com/cool-html-codes/ Important http://en.wikipedia.org/wiki/File:Nuvola_apps_important_blue.svg Reflow http://code.google.com/intl/sv-SE/speed/articles/reflow.html I have a dream http://bigdaddyseashell.wordpress.com/2008/04/04/early-morning-april-4/ Captain obvious http://bostonist.com/2005/05/28/tim_mccarver_still_sucks.php Godis http://maidies.blogg.se/2010/may/godis.html