SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
Richard Paul
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5
Kim Hunmin
 

What's hot (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
 

Viewers also liked

Javascript入门到高阶
Javascript入门到高阶Javascript入门到高阶
Javascript入门到高阶
ksky521
 

Viewers also liked (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
 

Similar to 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 V5a
rajivmordani
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
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
Dmitry 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 Suck
erockendude
 
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
Jarod Ferguson
 

Similar to 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
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
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
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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...
 
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)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

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