Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27392

Mutating the [[Prototype]] of an object

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!aioe.org!.POSTED!not-for-mail
From Richard Maher <maher_rjSPAMLESS@hotmail.com>
Newsgroups comp.lang.javascript
Subject Mutating the [[Prototype]] of an object
Date Sat, 18 Apr 2015 14:58:20 +0800
Organization Aioe.org NNTP Server
Lines 58
Message-ID <mgsvah$8fl$1@speranza.aioe.org> (permalink)
NNTP-Posting-Host uYFkdLFMFILrcerhBCvdBA.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.javascript:27392

Show key headers only | View raw


Hi,

I found this warning in the FireFox debugger today: -

"mutating the [[Prototype]] of an object will cause your code to run 
very slowly; instead create the object with the correct initial 
[[Prototype]] value using Object.create"

It's complaining about the code below (which, to be honest, is not 
really necessary and there are other ways to skin this particular cat).

How much more slowly will it make the code run? Is "mutating the 
prototype" really such a crime?

The requirement behind it is sometimes (user selected) I have a Circle 
and sometimes I have a Rectangle overlayed on a google map. Now, I don't 
want a whole lot of conditional logic so I sought to put a Rectangle peg 
in a Circle hole. (See what I did there :-)

Anyway I thought it useful to homogenize all functionality in to a 
radarView which could inherit from either circle or rectangle after they 
forked off google.maps.MVCObject

	
	function radarView(superBase)
	{
		this.__proto__ = superBase;
		
		if (this instanceof google.maps.Circle) {
			augmentCircle.apply(this);
		} else if (this instanceof google.maps.Rectangle) {
			augmentRectangle.apply(this);
		} else {
			Toolbox.reportError({header:"Internal error",
					message:"Inheriting from unknown object"});
		}

		this.doX = function(x){return "x is>" + x;};
		
		return this;
	}

	function augmentCircle()
	{
		this.moveBorder = function()
		{
			google.maps.event.trigger(radarCircle,"center_changed");
		}
	}

	function augmentRectangle()
	{
		this.moveBorder = function()
		{
			google.maps.event.trigger(radarRectangle,"boundsChanged");
		}
	}

Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread


Thread

Mutating the [[Prototype]] of an object Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2015-04-18 14:58 +0800

csiph-web