This document provides an overview of JavaScript concepts including variables, data types, objects, functions, conditionals, loops, callbacks, prototypes, this keyword, scope, closures, events, DOM manipulation, and asynchronous programming. It includes code examples to demonstrate these concepts such as defining variables, creating and accessing objects and their properties, writing functions with parameters and return values, if/else statements, for loops, and using callbacks with asynchronous functions.
60. // vad är this här?
avega = {
getOrgNumber: function(){
// vad är this här?
}
};
avega.companyInfo = {
getOrgNumber: function(){
// vad är this här?
}
};
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
... ...
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
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";
}
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