Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: Object.extend

  1. #1
    New Coder
    Join Date
    Sep 2009
    Location
    Croatia
    Posts
    38
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Object.extend

    Code:
    /**
     * Extends object with another objects properties.
     * Author: John Resigs <jeresig[at]gmail.com>
     * Modified by: Renato Bebić <renato.bebic[at]gmail.com>
     * Modified to distinct prototyped properties and extend
     * them to hosts prototype.
     * Tested and works on: Firefox 3.5, Chrome 3, Safari 4 
     *
     * @param object to extend with
     */
    Object.prototype.extend = function( object ) {
    	var property, getter, setter, target;
    	for ( property in object ) {
    		getter = object.__lookupGetter__( property );
    		setter = object.__lookupSetter__( property );
    		target = object.hasOwnProperty( property ) ? this : this.__proto__;
    		if ( getter )
    			target.__defineGetter__( property, getter );
    		else if ( setter )
    			target.__defineSetter__( property, setter );
    		else
    			target[ property ] = object[ property ];
    	}
    };
    Last edited by Renato Bebić; 09-28-2009 at 08:03 PM.


 

LinkBacks (?)

  1. 02-21-2014, 01:35 AM

Tags for this Thread

Posting Permissions

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