Results 1 to 13 of 13

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered 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);

  2. #2
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    var Shape = function() {name: 'Shape'};
    Shape , body name: 'Shape' .

    Shape -> name 'Shape', . .. {...} (members).
    , {} , .

    , .

    , JS , OO 5 () .

  3. #3
    Registered User
    Join Date: Oct:2008
    Location:
    Posts: 95
    tedych, !
    function():
    HTML Code:
    var Shape = {name: 'Shape'};
    Shape.prototype.toString = function() {return this.name;};
    
    print(Shape.name);
    : TypeError: Shape.prototype is undefined

    prototype :
    HTML Code:
    var Shape = {name: 'Shape'};
    Shape.toString = function() {return this.name;};
    
    print(Shape.toString());
    , prototype?

  4. #4
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    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'"); .

  5. #5
    Registered User
    Join Date: Mar:2006
    Location: Sofia
    Posts: 77
    Code:
    var Shape = function(){
    	//private 
    	var hidden = 'private';
    	//public 
    	this.name = 'Shape';
    	this.getHidden = function(){
    		return hidden;
    	};
    	this.getName = function(){
    		return this.name;
    	}
    };
    getName prototype ...
    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

  6. #6
    Registered User
    Join Date: Oct:2008
    Location:
    Posts: 95
    . object literal, . .. Object.create, , . - .

    butterflyz, :
    Code:
    var Shape = function(){
    	this.name = 'Shape';
    	this.getName = function(){
    		return this.name;
    	}
    };
    
    print(Shape.getName);
    : undefined.
    , ?

  7. #7
    a.k.a. Bibi Flower's Avatar
    Join Date: Aug:2006
    Location: Sofia, Bulgaria
    Posts: 562
    - . OOP js.
    js, , - . .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |