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


Groups > comp.lang.javascript > #27392

Mutating the [[Prototype]] of an object

From Richard Maher <maher_rjSPAMLESS@hotmail.com>
Newsgroups comp.lang.javascript
Subject Mutating the [[Prototype]] of an object
Date 2015-04-18 14:58 +0800
Organization Aioe.org NNTP Server
Message-ID <mgsvah$8fl$1@speranza.aioe.org> (permalink)

Show all headers | 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