.


:




:

































 

 

 

 


- javascript




 

- - JavaScript. , - , , , , , , JavaScript.

. - , . , Complex, , Complex .

JavaScript , C++, Java C#. JavaScript , - .

. JavaScript [1, 2] , , . - , C++ Java [3, 4]. - . JavaScript - . , JavaScript . , , JavaScript - , , C++ Java. JavaScript - .

, . , , . , , , , . JavaScript , . , C++ Java, . , . - JavaScript-, , , .

C++ Java . , , . [3]. JavaScript , - [2].

C++ Java : , , . , .

. . , Rectangle Rectangle width, . JavaScript . , - , , JavaScript , / -.

. , , , . C++ Java , JavaScript, C++ Java . , . area() Rectangle : a = r.area().

, , this. , , , . . JavaScript - . , , , .

C++ Java this, area() : return width * height.

JavaScript this : return this.width * this.height. JavaScript this , with, :

Rectangle.prototype.area = function() {

with(this) {

return width*height;

}

}

. Java C++ , , . , , .

, , . Number.MAX_VALUE JavaScript. , . , , JavaScript, . , JavaScript -. , Rectangle.UNIT 1x1 : Rectangle.UNIT = new Rectangle(1, 1). Rectangle -, JavaScript , , .

. , , ; , . Date.parse() . Date, Date.

-, this - , this -. this .

, . , , , , . , JavaScript . JavaScript, .

. - , C++, (private) , . , , /. JavaScript , , -.

, . Rectangle, :

function ImmutableRectangle(w, h) {

this.getWidth = function() { return w; }

this.getHeight = function() { return h; }

}

// -

ImmutableRectangle.prototype.area = function() {

return this.getWidth() * this.getHeight();

};

. C++, Java - . , . , . . , . JavaScript . JavaScript . JavaScript Object , , . Object.

JavaScript - . - ; Object(). , - Object.prototype. , , Complex Complex.prototype, Object.prototype. Complex, . , Complex.prototype. , , Object.prototype. - Complex , - Object, Complex.prototype Object.prototype. , Complex.prototype toString(), Object.prototype, Complex , toString() Complex.prototype .

JavaScript , Object; . , . , Rectangle, , . , - Rectangle Rectangle.prototype. JavaScript Rectanle PositionedRectangle:

// .

function Rectangle(w, h) {

this.width = w;

this.height = h;

}

Rectangle.prototype.area = function() { return this.width * this.height; }

//

function PositionedRectangle(x, y, w, h) {

Rectangle.call(this, w, h);

this.x = x;

this.y = y;

}

PositionedRectangle.prototype = new Rectangle();

// width height

delete PositionedRectangle.prototype.width;

delete PositionedRectangle.prototype.height;

// , PositionedRectangle

PositionedRectangle.prototype.constructor = PositionedRectangle;

//

PositionedRectangle.prototype.contains = function(x, y) {

return (x > this.x && x < this.x + this.width &&

y > this.y && y < this.y + this.height);

}

JavaScript , Object. , . - . - , constructor -. , -, , - .

PositionedRectangle, :

var r = new PositionedRectangle(2, 2, 2, 2);

print(r.contains(3, 3)); //

print(r.area()); //

print(r.x + ", " + r.y + ", " + r.width + ", " + r.height); //

// 3

print(r instanceof PositionedRectangle &&

r instanceof Rectangle &&

r instanceof Object);

. . C++ Java , , , . C++ , , [3].

JavaScript - Object [2]. JavaScript .

JavaScript, , , , (overrides) . , , . . . , . . , Rectangle toString() :

Rectangle.prototype.toString = function() {

return "[" + this.width + ", " + this.height + "]";

}

PositionedRectangle, , , . , width height . :

PositionedRectangle.prototype.toString = function() {

return "(" + this.x + "," + this.y + ") " + //

Rectangle.prototype.toString.apply(this); //

}

toString() - . apply(), , . PositionedRectangle.prototype superclass, , :

PositionedRectangle.prototype.toString = function() {

return "(" + this.x + ", " + this.y + ") " + //

this.superclass.prototype.toString.apply(this);

}

superclass . , .

 

. - , JavaScript , . , , , , , . , , - JavaScript, , - [5]. , -.

:

1. . JavaScript. . . . : _, 2008. 992 .

2. Danny Goodman, Michael Morrison, Paul Novitski, Tia Gustaff Rayl. JavaScript Bible: Seventh Edition. - Wiley Publishing, Inc., 2010. 1186 pp.

3. .., .. : . : - .. . , 2006. 376 .

4. .., .., - .. ij : . : - .. . , 2010. 408 .

5. Jeremy Keith, Jeffrey Sambells. DOM Scripting: Web Design with JavaScript and the Document Object Model: Second Edition. Apress, 2010. 337 pp.

 

 

̲Ͳ

658

 

..

 





:


: 2017-02-25; !; : 729 |


:

:

, .
==> ...

1465 - | 1375 -


© 2015-2024 lektsii.org - -

: 0.042 .