SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Prototypal Inheritance - q's about crockfords object method and power constructor

    I am doing a little playing around with crockfords object method and power constructers. http://video.yahoo.com/video/play?vid=111585

    Something I don't understand however is why I don't have access to the objects constructor function. Is this something that I need to set implicitly like so

    that.constructor = Author;

    Any help would be great? Cause I am all out of ideas Cheers. Full source below.


    Code:
    (function(){
    
        // crockfords object method 
        function object(o) {
            function F() {}
            F.prototype = o;
            return new F();
        }	
        
        // person (object to inherit from)
        person = function() {
    	 		
    	return {
    			
    		setName: function(name) {
    			this.name = name;
    		},
    		getName: function() {
    			return this.name;
    		}
    	}
    
        }();
        
        // power constructor
        function Author(name) {
    	var that = object(person);
    	that.setName(name);
    	return that;
        } 
    
        // instance of Author
        var scott = Author("Scott");
        alert(Scott.constructor);
    
    	
    })();

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Try using a lowercase s
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

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