Results 1 to 13 of 13
Thread: JavaScript oop
Hybrid View
-
24th May 2013 12:39 #1Registered User
Join Date: Oct:2008
Location:
Posts: 95
JavaScript oop
,
Javascript. , . , .
1. :
**********************HTML Code:var Shape = function() {name: 'Shape'}; print(Shape.name); //----- //:
?HTML Code:var Shape = {name: 'Shape'}; print(Shape.name); //----------------- //: Shape
2. :
HTML Code:var Shape = function() {name: 'Shape'}; Shape.prototype.toString = function() {return this.name;}; print(Shape.name);
-
24th May 2013 12:49 #2
var Shape = function() {name: 'Shape'};
Shape , body name: 'Shape' .
Shape -> name 'Shape', . .. {...} (members).
, {} , .
, .
, JS , OO 5 () .
-
24th May 2013 12:57 #3Registered User
Join Date: Oct:2008
Location:
Posts: 95
tedych, !
function():
: TypeError: Shape.prototype is undefinedHTML Code:var Shape = {name: 'Shape'}; Shape.prototype.toString = function() {return this.name;}; print(Shape.name);
prototype :
, prototype?HTML Code:var Shape = {name: 'Shape'}; Shape.toString = function() {return this.name;}; print(Shape.toString());
-
24th May 2013 13:33 #4
function Shape() {this.name = 'Shape'};
var myshape = new Shape();
Shape.prototype.toString = function() {return this.name;};
alert(myshape.toString());
.. .prototype constructor function-a Shape().
.. , .
var , : var Shape = new Function ("this.name = 'Shape'"); .
-
24th May 2013 14:19 #5Registered User
Join Date: Mar:2006
Location: Sofia
Posts: 77
getName prototype ...Code:var Shape = function(){ //private var hidden = 'private'; //public this.name = 'Shape'; this.getHidden = function(){ return hidden; }; this.getName = function(){ return this.name; } };Last edited by butterflyz; 24th May 2013 at 15:34.
i5 2500k | 4.8ghz 1.334v | hyper 212+ | 4GB 1600mhz Kingston 8-9-8-24 | HDD 660GB | Asrock Pro3 P67 b2
-
24th May 2013 17:14 #6Registered User
Join Date: Oct:2008
Location:
Posts: 95
. object literal, . .. Object.create, , . - .
butterflyz, :
: undefined.Code:var Shape = function(){ this.name = 'Shape'; this.getName = function(){ return this.name; } }; print(Shape.getName);
, ?
-
1st June 2013 11:09 #7




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in