Introduction to JavaScript (part1)

Содержание

Слайд 2

Слайд 3

What is JavaScript ? JavaScript is a lightweight, interpreted programming language.

What is JavaScript ?

JavaScript is a lightweight, interpreted programming language.

Слайд 4

What is JavaScript ? JavaScript is a lightweight, interpreted programming language.

What is JavaScript ?

JavaScript is a lightweight, interpreted programming language.

Advantages
Less server

interaction
Immediate feedback to the visitors
Increased interactivity
Richer interfaces
Слайд 5

What is JavaScript ? JavaScript is a lightweight, interpreted programming language.

What is JavaScript ?

JavaScript is a lightweight, interpreted programming language.

Advantages
Less server

interaction
Immediate feedback to the visitors
Increased interactivity
Richer interfaces

Limitations
Client-side JavaScript does not allow the reading or writing of files.
JavaScript doesn't have any multithreading or multiprocess capabilities.

Слайд 6

JavaScript Where To The Tag document.getElementById("demo").innerHTML = "My First JavaScript";

JavaScript Where To

The

Слайд 7

JavaScript Where To The Tag document.getElementById("demo").innerHTML = "My First JavaScript"; JavaScript

JavaScript Where To

The
JavaScript in





Слайд 8

JavaScript Where To The Tag document.getElementById("demo").innerHTML = "My First JavaScript"; JavaScript

JavaScript Where To

The
JavaScript in





JavaScript in

A Paragraph





Слайд 9

External JavaScript

External JavaScript







Слайд 10

External JavaScript Advantages: It separates HTML and code. It makes HTML

External JavaScript







Advantages:
It separates HTML and code.
It makes HTML and

JavaScript easier to read and maintain
Cached JavaScript files can speed up page loads.
Слайд 11

JavaScript Syntax Comments: // var x = 5 + 6; I

JavaScript Syntax

Comments:
// var x = 5 + 6; I will not

be executed
var x = 5; // Declare x, give it the value of 5
/*
Not all JavaScript statements are "executable commands".
Anything after double slashes // is treated as a comment.
Comments are ignored, and will not be executed:
*/
All JavaScript identifiers are case sensitive.
lastName != lastname
JavaScript uses the Unicode character set.
Слайд 12

JavaScript Display Possibilities Writing into the HTML output using document.write(). Writing

JavaScript Display Possibilities

Writing into the HTML output using document.write().
Writing into an

alert box, using window.alert().
Writing into the browser console, using console.log().
Writing into an HTML element, using innerHTML.
Слайд 13

JavaScript Display Possibilities Writing into the HTML output using document.write(). Writing

JavaScript Display Possibilities

Writing into the HTML output using document.write().
Writing into an

alert box, using window.alert().
Writing into the browser console, using console.log().
Writing into an HTML element, using innerHTML.
document.write(5 + 6);
document.getElementById("demo").innerHTML = 5 + 6;
window.alert(5 + 6);
console.log(5 + 6);
Слайд 14

JavaScript Statements

JavaScript Statements

Слайд 15

Add text 1 Add text 2 Add text 3 Click to

Add text 1
Add text 2
Add text 3

Click to ad text

Numbers are

written with or without decimals

Strings are written with double or single quotes

Values

10.50
1001
123e5

"text"
'other one'

Слайд 16

Add text 1 Add text 2 Add text 3 Click to

Add text 1
Add text 2
Add text 3

Click to ad text

Numbers are

written with or without decimals

Strings are written with double or single quotes

Values

Variables

10.50
1001
123e5

"text"
'other one'

var x;
x = 6;

Variables are used to store values

The var keyword to define variables

var y = 5;
var z = y + 1;

Слайд 17

JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified

JavaScript Identifiers

All JavaScript variables (and JavaScript functions) must be identified with

unique names.
The general rules for constructing a names for variables (unique identifiers) are:
Names must begin with a letter
Names can also begin with $ and _
Names can contain letters, digits, underscores, and dollar signs.
Names are case sensitive (y and Y are different variables)
Can be used “camelCase”
Reserved words (like JavaScript keywords) cannot be used as names
Слайд 18

JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified

JavaScript Identifiers

All JavaScript variables (and JavaScript functions) must be identified with

unique names.
The general rules for constructing a names for variables (unique identifiers) are:
Names must begin with a letter
Names can also begin with $ and _
Names can contain letters, digits, underscores, and dollar signs.
Names are case sensitive (y and Y are different variables)
Can be used “camelCase”
Reserved words (like JavaScript keywords) cannot be used as names
JavaScript variables can hold many types of data.
Слайд 19

JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified

JavaScript Identifiers

All JavaScript variables (and JavaScript functions) must be identified with

unique names.
The general rules for constructing a names for variables (unique identifiers) are:
Names must begin with a letter
Names can also begin with $ and _
Names can contain letters, digits, underscores, and dollar signs.
Names are case sensitive (y and Y are different variables)
Can be used “camelCase”
Reserved words (like JavaScript keywords) cannot be used as names
JavaScript variables can hold many types of data.
In JavaScript, the equal sign (=) is an "assignment" operator, is not an "equal to" operator.
x = x + 5
Слайд 20

JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified

JavaScript Identifiers

All JavaScript variables (and JavaScript functions) must be identified with

unique names.
The general rules for constructing a names for variables (unique identifiers) are:
Names must begin with a letter
Names can also begin with $ and _
Names can contain letters, digits, underscores, and dollar signs.
Names are case sensitive (y and Y are different variables)
Can be used “camelCase”
Reserved words (like JavaScript keywords) cannot be used as names
JavaScript variables can hold many types of data.
In JavaScript, the equal sign (=) is an "assignment" operator, is not an "equal to" operator.
x = x + 5
If you put quotes around a numeric value, it will be treated as a text string.
var pi = '3.14';
var constPi=3.14;
Слайд 21

Declaring (Creating) JavaScript Variables var carName; //Variable declared without a value

Declaring (Creating) JavaScript Variables

var carName;
//Variable declared without a value will

have the value undefined.
carName = "Volvo";
//or
var carName = "Volvo";
//For many Variables start the statement with var and separate the variables by comma:
var lastName = "Doe",
age = 30,
job = "carpenter";
//or
var lastName = "Doe";
var age = 30;
var job = "carpenter";
Слайд 22

Global variables are evil!!!! evil = 'Variable declaration without var'

Global variables are evil!!!!

evil = 'Variable declaration without var'

Слайд 23

JavaScript Keywords (reserved words)

JavaScript Keywords
(reserved words)

Слайд 24

JavaScript Keywords (reserved words)

JavaScript Keywords
(reserved words)

Слайд 25

var albums = 16; // Number assigned by a number literal

var albums = 16; // Number assigned by a number literal
var

songs = albums * 10; // Number assigned by an expression literal
var title = "Highway to Hell"; // String assigned by a string literal
var members = [
"Angus Young",
"Phil Rudd",
"Cliff Williams",
"Brian Johnson",
"Stevie Young"
]; // Array assigned by an array literal
var band = {name:"AC/DC", startYear:1973}; // Object assigned by an object literal

JavaScript Data Types

Слайд 26

JavaScript Data Types Number: Integer Float Infinity NaN String: “text1” ‘text2’

JavaScript Data Types

Number:
Integer
Float
Infinity
NaN

String:
“text1”
‘text2’

Boolean:
true
false

Object:
object
null
Array
Function

undefined

Слайд 27

The typeof Operator typeof "Cat"

The typeof Operator

typeof "Cat"

Слайд 28

The typeof Operator typeof "Cat" // Returns string typeof 3.14

The typeof Operator

typeof "Cat" // Returns string
typeof 3.14

Слайд 29

The typeof Operator typeof "Cat" // Returns string typeof 3.14 // Returns number typeof false

The typeof Operator

typeof "Cat" // Returns string
typeof 3.14 // Returns number
typeof

false
Слайд 30

The typeof Operator typeof "Cat" // Returns string typeof 3.14 //

The typeof Operator

typeof "Cat" // Returns string
typeof 3.14 // Returns number
typeof

false // Returns boolean
typeof [1,2,3,4]
Слайд 31

The typeof Operator typeof "Cat" // Returns string typeof 3.14 //

The typeof Operator

typeof "Cat" // Returns string
typeof 3.14 // Returns number
typeof

false // Returns boolean
typeof [1,2,3,4] // Returns object
typeof {name:'Ann', age:17}
Слайд 32

The typeof Operator typeof "Cat" // Returns string typeof 3.14 //

The typeof Operator

typeof "Cat" // Returns string
typeof 3.14 // Returns number
typeof

false // Returns boolean
typeof [1,2,3,4] // Returns object
typeof {name:'Ann', age:17} // Returns object




The typeof operator returns the type of a variable or an expression.






Слайд 33

Strings Length: var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var sln = txt.length;

Strings

Length:
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sln = txt.length;

Слайд 34

Strings Length: var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var sln = txt.length; Special Characters: * escape character \

Strings

Length:
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sln = txt.length;

Special Characters:

* escape character \

Слайд 35

Strings Created from literals: var x = "Lorem ipsum";

Strings

Created from literals:
var x = "Lorem ipsum";

Слайд 36

Strings Created from literals: var x = "Lorem ipsum"; Defined as

Strings

Created from literals:
var x = "Lorem ipsum";
Defined as objects:
var y =

new String("Lorem ipsum");
Слайд 37

Strings Created from literals: var x = "Lorem ipsum"; Defined as

Strings

Created from literals:
var x = "Lorem ipsum";
Defined as objects:
var y =

new String("Lorem ipsum");

console.log(typeof x); //?
console.log(typeof y); //?
console.log(x === y); //?

Слайд 38

Strings Created from literals: var x = "Lorem ipsum"; Defined as

Strings

Created from literals:
var x = "Lorem ipsum";
Defined as objects:
var y =

new String("Lorem ipsum");

console.log(typeof x); //?
console.log(typeof y); //?
console.log(x === y); //?

Don't create String objects. They slow down execution speed!

Слайд 39

String Methods

String Methods

Слайд 40

String Methods

String Methods

Слайд 41

String Methods Finding a String in a String: indexOf() var str

String Methods

Finding a String in a String:
indexOf()
var str = "The

indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string";
var pos = str.indexOf("index");
Слайд 42

String Methods Finding a String in a String: indexOf() var str

String Methods

Finding a String in a String:
indexOf()
var str = "The

indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string";
var pos = str.indexOf("index");
lastIndexOf()
var str = "The lastIndexOf() method returns the index of the last occurrence of a specified text in a string";
var pos = str.lastIndexOf("index");
Слайд 43

String Methods Finding a String in a String: indexOf() var str

String Methods

Finding a String in a String:
indexOf()
var str = "The

indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string";
var pos = str.indexOf("index");
lastIndexOf()
var str = "The lastIndexOf() method returns the index of the last occurrence of a specified text in a string";
var pos = str.lastIndexOf("index");
Return -1 if the text is not found!
JavaScript counts positions from zero.
Both methods accept a second parameter as the starting position for the search.
Слайд 44

String Methods Finding a String in a String: indexOf() var str

String Methods

Finding a String in a String:
indexOf()
var str = "The

indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string";
var pos = str.indexOf("index");
lastIndexOf()
var str = "The lastIndexOf() method returns the index of the last occurrence of a specified text in a string";
var pos = str.lastIndexOf("index");
Return -1 if the text is not found!
JavaScript counts positions from zero.
Both methods accept a second parameter as the starting position for the search.
search()
var str = "The search() can work with regular expressions and returns the position of the match";
var pos = str.search("search");
Слайд 45

String Methods Extracting String Parts: slice(start [, end]) var str =

String Methods

Extracting String Parts:
slice(start [, end])
var str = "The

method takes 2 parameters: the starting index (position), and the ending index (position).";
var res = str.slice(4,10);
Слайд 46

String Methods Extracting String Parts: slice(start [, end]) var str =

String Methods

Extracting String Parts:
slice(start [, end])
var str = "The

method takes 2 parameters: the starting index (position), and the ending index (position).";
var res = str.slice(4,10);
or
var str = "If a parameter is negative, the position is counted from the end of the string.";
var res = str.slice(-7,-1);
Слайд 47

String Methods Extracting String Parts: slice(start [, end]) var str =

String Methods

Extracting String Parts:
slice(start [, end])
var str = "The

method takes 2 parameters: the starting index (position), and the ending index (position).";
var res = str.slice(4,10);
or
var str = "If a parameter is negative, the position is counted from the end of the string.";
var res = str.slice(-7,-1);
Try with one parameter!!!
Слайд 48

String Methods Replacing String Content: replace(regexp|substr, newSubStr|function) str = "One coffee, please!"; var n = str.replace("coffee","tea");

String Methods

Replacing String Content:
replace(regexp|substr, newSubStr|function)
str = "One coffee, please!";
var

n = str.replace("coffee","tea");
Слайд 49

String Methods Replacing String Content: replace(regexp|substr, newSubStr|function) str = "One coffee,

String Methods

Replacing String Content:
replace(regexp|substr, newSubStr|function)
str = "One coffee, please!";
var n

= str.replace("coffee","tea");
Converting to Upper and Lower Case:
var text1 = "Hello World!";
var text2 = text1.toUpperCase();
var text3 = text1.toLowerCase();
Слайд 50

String Methods concat(string1, string2, ..., stringX) The concat() method can be

String Methods

concat(string1, string2, ..., stringX)
The concat() method can be used instead

of the plus operator.
var text = "Hello" + " " + "World!";
var text = "Hello".concat(" ","World!");
Converting a String to an Array:
split(reg|substr)
var txt = "a,b,c,d,e"; // String
txt.split(","); // Split on commas
var txt = "a bb c d e"; // String
txt.split(" "); // Split on spaces
var txt = "a|b|c|d|e"; // String
txt.split("|"); // Split on pipe
Слайд 51

Numbers By default, Javascript displays numbers as base 10 decimals. Base

Numbers

By default, Javascript displays numbers as base 10 decimals.
Base 16 (hex),

base 8 (octal), or base 2 (binary) can be used.
var myNumber = 128;
myNumber.toString(16); // returns 80
myNumber.toString(8); // returns 200
myNumber.toString(2); // returns 10000000
Слайд 52

Numbers Infinity // Execute until Infinity function myFunction() { var myNumber

Numbers

Infinity
// Execute until Infinity

or
var x = 2 / 0;

Слайд 53

Numbers Infinity // Execute until Infinity function myFunction() { var myNumber

Numbers

Infinity
// Execute until Infinity

or
var x = 2 / 0;
NaN - Not a Number
var x = 100 / "Apple";
var x = 100 / "10";
isNaN(x); // returns true because x is Not a Number

Слайд 54

Numbers Created from literals: var x = 123;

Numbers

Created from literals:
var x = 123;

Слайд 55

Numbers Created from literals: var x = 123; Defined as objects: var y = new Number(123);

Numbers

Created from literals:
var x = 123;
Defined as objects:
var y = new

Number(123);
Слайд 56

Numbers Created from literals: var x = 123; Defined as objects:

Numbers

Created from literals:
var x = 123;
Defined as objects:
var y = new

Number(123);
typeof x; //?
typeof y; //?
(x === y) //?
Слайд 57

Numbers Created from literals: var x = 123; Defined as objects:

Numbers

Created from literals:
var x = 123;
Defined as objects:
var y = new

Number(123);
typeof x; //?
typeof y; //?
(x === y) //?
Don't create Number objects. They slow down execution speed!
Слайд 58

Global methods for numbers Try: x = true; Number(x); x =

Global methods for numbers

Try:
x = true;
Number(x);
x = false;
Number(x);
x =

new Date();
Number(x);
x = "10"
Number(x);
x = "10 20"
Number(x);

parseInt("10");
parseInt("10.33");
parseInt("10 20 30");
parseInt("10 years");
parseInt("years 10");

parseFloat("10");
parseFloat("10.33");
parseFloat("10 20 30");
parseFloat("10 years");
parseFloat("years 10");

Слайд 59

Number methods toString() var x = 123; x.toString(); // returns 123

Number methods

toString()
var x = 123;
x.toString(); // returns 123 from variable x
(123).toString();

// returns 123 from literal 123
(100 + 23).toString(); // returns 123 from expression 100 + 23
Слайд 60

Number methods toString() var x = 123; x.toString(); // returns 123

Number methods

toString()
var x = 123;
x.toString(); // returns 123 from variable x
(123).toString();

// returns 123 from literal 123
(100 + 23).toString(); // returns 123 from expression 100 + 23
toFixed(precision)
returns a string, with the number written with a specified number of decimals
var x = 9.656;
x.toFixed(0); // returns 10
x.toFixed(2); // returns 9.66
x.toFixed(4); // returns 9.6560
Слайд 61

Number methods toString() var x = 123; x.toString(); // returns 123

Number methods

toString()
var x = 123;
x.toString(); // returns 123 from variable x
(123).toString();

// returns 123 from literal 123
(100 + 23).toString(); // returns 123 from expression 100 + 23
toFixed(precision)
returns a string, with the number written with a specified number of decimals
var x = 9.656;
x.toFixed(0); // returns 10
x.toFixed(2); // returns 9.66
x.toFixed(4); // returns 9.6560
toPrecision(precision)
returns a string, with a number written with a specified length
var x = 9.656;
x.toPrecision(); // returns 9.656
x.toPrecision(2); // returns 9.7
x.toPrecision(4); // returns 9.656
Слайд 62

Booleans Everything With a Real Value is True: Boolean(100); Boolean(3.14); Boolean(-15);

Booleans

Everything With a Real Value is True:
Boolean(100);
Boolean(3.14);
Boolean(-15);
Boolean("Hello");
Boolean('false');
Boolean(1 + 7 + 3.14);

Слайд 63

Booleans Everything With a Real Value is True: Boolean(100); Boolean(3.14); Boolean(-15);

Booleans

Everything With a Real Value is True:
Boolean(100);
Boolean(3.14);
Boolean(-15);
Boolean("Hello");
Boolean('false');
Boolean(1 + 7 + 3.14);

Everything

Without a Real Value is False:
Boolean(0);
Boolean(-0);
Boolean(x);
Boolean("");
Boolean(null);
Boolean(false);
Boolean(10 / "A");
Слайд 64

Arrays JavaScript arrays are used to store multiple values in a

Arrays

JavaScript arrays are used to store multiple values in a single

variable.
var array-name = [item1, item2, ...];
var cars = ["Saab", "Volvo", "BMW"];
var cars = new Array("Saab", "Volvo", "BMW");
Слайд 65

Arrays JavaScript arrays are used to store multiple values in a

Arrays

JavaScript arrays are used to store multiple values in a single

variable.
var array-name = [item1, item2, ...];
var cars = ["Saab", "Volvo", "BMW"];
var cars = new Array("Saab", "Volvo", "BMW");
Access the Elements of an Array:
var name = cars[0];
cars[0] = "Opel";
[0] is the first element in an array. [1] is the second. Array indexes start with 0.
In JavaScript, arrays use numbered indexes.
Слайд 66

Arrays JavaScript arrays are used to store multiple values in a

Arrays

JavaScript arrays are used to store multiple values in a single

variable.
var array-name = [item1, item2, ...];
var cars = ["Saab", "Volvo", "BMW"];
var cars = new Array("Saab", "Volvo", "BMW");
Access the Elements of an Array:
var name = cars[0];
cars[0] = "Opel";
[0] is the first element in an array. [1] is the second. Array indexes start with 0.
In JavaScript, arrays use numbered indexes.
Looping Array Elements
var index,
text="";
var fruits = ["Banana", "Orange", "Apple", "Mango"];
for (index = 0; index < fruits.length; index++) {
text += fruits[index];
}
console.log(text);
Слайд 67

Arrays Avoid new Array()! Try: var points = new Array(40, 100); var points = new Array(40);

Arrays

Avoid new Array()!
Try:
var points = new Array(40, 100);
var points =

new Array(40);
Слайд 68

Arrays Avoid new Array()! Try: var points = new Array(40, 100);

Arrays

Avoid new Array()!
Try:
var points = new Array(40, 100);
var points =

new Array(40);
How to Recognize an Array?
var fruits = ["Banana", "Orange", "Apple", "Mango"];
typeof fruits;
Слайд 69

Arrays Avoid new Array()! Try: var points = new Array(40, 100);

Arrays

Avoid new Array()!
Try:
var points = new Array(40, 100);
var points =

new Array(40);
How to Recognize an Array?
var fruits = ["Banana", "Orange", "Apple", "Mango"];
typeof fruits;
better

Слайд 70

Array Methods Converting Arrays to Strings var fruits = ["Banana", "Orange",

Array Methods

Converting Arrays to Strings
var fruits = ["Banana", "Orange", "Apple", "Mango"];
valueOf()
document.getElementById("demo").innerHTML

= fruits.valueOf();
Слайд 71

Array Methods Converting Arrays to Strings var fruits = ["Banana", "Orange",

Array Methods

Converting Arrays to Strings
var fruits = ["Banana", "Orange", "Apple", "Mango"];
valueOf()
document.getElementById("demo").innerHTML

= fruits.valueOf();
toString()
document.getElementById("demo").innerHTML = fruits.toString();
Слайд 72

Array Methods Converting Arrays to Strings var fruits = ["Banana", "Orange",

Array Methods

Converting Arrays to Strings
var fruits = ["Banana", "Orange", "Apple", "Mango"];
valueOf()
document.getElementById("demo").innerHTML

= fruits.valueOf();
toString()
document.getElementById("demo").innerHTML = fruits.toString();
join(str)
document.getElementById("demo").innerHTML = fruits.join(" * ");
Слайд 73

Array Methods Add and remove elements var fruits = ["Banana", "Orange","Apple",

Array Methods

Add and remove elements
var fruits = ["Banana", "Orange","Apple", "Mango"];
pop() removes

the last element from an array
fruits.pop();
Слайд 74

Array Methods Add and remove elements var fruits = ["Banana", "Orange","Apple",

Array Methods

Add and remove elements
var fruits = ["Banana", "Orange","Apple", "Mango"];
pop() removes

the last element from an array
fruits.pop();
push() method adds a new element to an array (at the end)
fruits.push("Kiwi");
Слайд 75

Array Methods Add and remove elements var fruits = ["Banana", "Orange","Apple",

Array Methods

Add and remove elements
var fruits = ["Banana", "Orange","Apple", "Mango"];
pop() removes

the last element from an array
fruits.pop();
push() method adds a new element to an array (at the end)
fruits.push("Kiwi");
shift() removes the first element of an array, and "shifts" all other elements one place down
fruits.shift();
Слайд 76

Array Methods Add and remove elements var fruits = ["Banana", "Orange","Apple",

Array Methods

Add and remove elements
var fruits = ["Banana", "Orange","Apple", "Mango"];
pop() removes

the last element from an array
fruits.pop();
push() method adds a new element to an array (at the end)
fruits.push("Kiwi");
shift() removes the first element of an array, and "shifts" all other elements one place down
fruits.shift();
unshift() adds a new element to an array (at the beginning), and "unshifts" older elements
fruits.unshift("Lemon");
The shift() method returns the string that was "shifted out".
The unshift() method returns the new array length.
Слайд 77

Array Methods Add and remove elements var fruits = ["Banana", "Orange","Apple",

Array Methods

Add and remove elements
var fruits = ["Banana", "Orange","Apple", "Mango"];
splice(index[, deleteCount,

elem1, ..., elemN])
fruits.splice(2, 0, "Lemon", "Kiwi");
The first parameter (2) defines the position where new elements should be added (spliced in).
The second parameter (0) defines how many elements should be removed.
The rest of the parameters ("Lemon" , "Kiwi") define the new elements to be added.
Слайд 78

Array Methods var fruits = ["Banana", "Orange","Apple", "Mango"]; sort() fruits.sort(); reverse() fruits.reverse();

Array Methods

var fruits = ["Banana", "Orange","Apple", "Mango"];
sort()
fruits.sort();
reverse()
fruits.reverse();

Слайд 79

Objects Hobbit

Objects

Hobbit

Слайд 80

Objects Hobbit Hobbit.name = “Bilbo” Hobbit.age = 132 Hobbit.address = Shire

Objects

Hobbit
Hobbit.name = “Bilbo”
Hobbit.age = 132
Hobbit.address = Shire
Hobbit.hair = true

Hobbit.walk()
Hobbit.fight()
Hobbit.keepRing()

Слайд 81

Objects Hobbit Hobbit.name = “Bilbo” Hobbit.age = 132 Hobbit.address = Shire

Objects

Hobbit
Hobbit.name = “Bilbo”
Hobbit.age = 132
Hobbit.address = Shire
Hobbit.hair = true

Gollum

Hobbit.walk()
Hobbit.fight()
Hobbit.keepRing()

Слайд 82

Objects Hobbit Hobbit.name = “Bilbo” Hobbit.age = 132 Hobbit.address = Shire

Objects

Hobbit
Hobbit.name = “Bilbo”
Hobbit.age = 132
Hobbit.address = Shire
Hobbit.hair = true

Gollum
gollum = new

Hobbit();
gollum.name = “Gollum”
gollum.age = null
gollum.address = cave
gollum.hair = false

Hobbit.walk()
Hobbit.fight()
Hobbit.keepRing()

gollum.eatFreshFish()

Слайд 83

Objects All hobbits have the same properties, but the property values

Objects

All hobbits have the same properties, but the property values differ

from one to one.
All hobbits have the same methods, but the methods are performed at different times.
var person = {
firstName:"Bilbo", //property
lastName:"Baggins", //property
age:132, //property
eyeColor:"blue", //property
walk: function(){
console.log('walking to Mordor'); //method
}
};
Слайд 84

Objects All hobbits have the same properties, but the property values

Objects

All hobbits have the same properties, but the property values differ

from one to one.
All hobbits have the same methods, but the methods are performed at different times.
var person = {
firstName:"Bilbo", //property
lastName:"Baggins", //property
age:132, //property
eyeColor:"blue", //property
walk: function(){
console.log('walking to Mordor'); //method
}
};
person.address = "Shire";
person.fight = function(){
console.log('blood');
};
Слайд 85

Objects var х = lastName; console.log(person.firstName); console.log(person[х]); person.walk();

Objects

var х = lastName;
console.log(person.firstName);
console.log(person[х]);
person.walk();