<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Seeking JavaScript Help</title>
	<atom:link href="http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/feed/" rel="self" type="application/rss+xml" />
	<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/</link>
	<description>Things that Eric A. Meyer, CSS expert, writes about on his personal Web site; it&#039;s largely Web standards and Web technology, but also various bits of culture, politics, personal observations, and other miscellaneous stuff</description>
	<lastBuildDate>Fri, 10 May 2013 11:50:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Lachlan Hunt</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-437150</link>
		<dc:creator>Lachlan Hunt</dc:creator>
		<pubDate>Sun, 18 Jan 2009 19:15:34 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-437150</guid>
		<description><![CDATA[Here&#039;s an alternative using the getters and setters syntax supported by Firefox, Opera and Safari.  If support for IE is needed, than this won&#039;t be suitable.  (IE8 has added support for getters and setters recently, but unfortunately, it seems the syntax defined by ECMAScript 3.1 and implemented by IE is not entirely compatible with that used by the others.)

There are various improvements that could be made to optimise this, but it&#039;s difficult to know what can be changed without known what it&#039;s for or how it&#039;s meant to be used.  I&#039;m not even sure some of the changes I made to this version are suitable for what you need. But I&#039;m sure you can use this to get you started anyway.

&lt;pre&gt;
&lt;code&gt;function Detonation(name, lat, lon, yieldValue) {
    var self = this; // Keep a reference to this object availale
    var gz = new GLatLng(lat, lon);

    // Use _yeild because yeild is a reserved keyword in JavaScript 1.7
    var scale, _yield;
    
    // Use a setter function to recalculate the scale when yield is set
    this.__defineSetter__(&quot;yield&quot;, function(value) {
	    _yield = value;
        scale = Math.pow(_yield, 1/3);
	} );

    this.__defineGetter__(&quot;yield&quot;, function() {
        return _yield;
    } );
    this.yield = yieldValue;

    this.name = name;
    
    // Use getters here so that these values can&#039;t be changed externally
    // If you need them to be settable externally, use __defineSetter__ to
    // define setter functions for lat and lon that recalculate gz when set
    this.__defineGetter__(&quot;lat&quot;, function() { return lat; };
    this.__defineGetter__(&quot;lon&quot;, function() { return lon; };
    this.__defineGetter__(&quot;gz&quot;, function() { return gz; };
    
    // Use getters for each of these so the value is recalculated
    // based on the current scale value
    this.overpressure = {
        get p30() { return 0.108 * scale; },
        get p15() { return 0.153 * scale; },
        get p10() { return 0.185 * scale; },
        get  p5() { return 0.281 * scale; },
        get  p1() { return 0.725 * scale; }
    };

    // Similarly, use getters for these properties so their values are calculated
    // based on the current values when needed
    this.psi30 = {
        get radius() { return self.overpressure.p30 },
        overlay: {
            get points() { return makePoints(self.gz, self.overpressure.p30) }
        }
    };
    this.psi15 = {
        get radius() { return self.overpressure.p15 },
        overlay: {
            get points() { return makePoints(self.gz, self.overpressure.p15) }
        }
    };
    this.therm20 = {
        get radius() { thermDist(20, self.yield , 0.33, conditions.visibility) },
        overlay: {
            get points() { return makePoints(self.gz, self.psi15.radius * scale) }
        }
    };
    // ...and so on...
}&lt;/code&gt;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s an alternative using the getters and setters syntax supported by Firefox, Opera and Safari.  If support for IE is needed, than this won&#8217;t be suitable.  (IE8 has added support for getters and setters recently, but unfortunately, it seems the syntax defined by ECMAScript 3.1 and implemented by IE is not entirely compatible with that used by the others.)</p>
<p>There are various improvements that could be made to optimise this, but it&#8217;s difficult to know what can be changed without known what it&#8217;s for or how it&#8217;s meant to be used.  I&#8217;m not even sure some of the changes I made to this version are suitable for what you need. But I&#8217;m sure you can use this to get you started anyway.</p>
<pre>
<code>function Detonation(name, lat, lon, yieldValue) {
    var self = this; // Keep a reference to this object availale
    var gz = new GLatLng(lat, lon);

    // Use _yeild because yeild is a reserved keyword in JavaScript 1.7
    var scale, _yield;
    
    // Use a setter function to recalculate the scale when yield is set
    this.__defineSetter__("yield", function(value) {
	    _yield = value;
        scale = Math.pow(_yield, 1/3);
	} );

    this.__defineGetter__("yield", function() {
        return _yield;
    } );
    this.yield = yieldValue;

    this.name = name;
    
    // Use getters here so that these values can't be changed externally
    // If you need them to be settable externally, use __defineSetter__ to
    // define setter functions for lat and lon that recalculate gz when set
    this.__defineGetter__("lat", function() { return lat; };
    this.__defineGetter__("lon", function() { return lon; };
    this.__defineGetter__("gz", function() { return gz; };
    
    // Use getters for each of these so the value is recalculated
    // based on the current scale value
    this.overpressure = {
        get p30() { return 0.108 * scale; },
        get p15() { return 0.153 * scale; },
        get p10() { return 0.185 * scale; },
        get  p5() { return 0.281 * scale; },
        get  p1() { return 0.725 * scale; }
    };

    // Similarly, use getters for these properties so their values are calculated
    // based on the current values when needed
    this.psi30 = {
        get radius() { return self.overpressure.p30 },
        overlay: {
            get points() { return makePoints(self.gz, self.overpressure.p30) }
        }
    };
    this.psi15 = {
        get radius() { return self.overpressure.p15 },
        overlay: {
            get points() { return makePoints(self.gz, self.overpressure.p15) }
        }
    };
    this.therm20 = {
        get radius() { thermDist(20, self.yield , 0.33, conditions.visibility) },
        overlay: {
            get points() { return makePoints(self.gz, self.psi15.radius * scale) }
        }
    };
    // ...and so on...
}</code>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: JFSIII</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436874</link>
		<dc:creator>JFSIII</dc:creator>
		<pubDate>Sat, 17 Jan 2009 04:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436874</guid>
		<description><![CDATA[Piggy-backing on comments and code from Micheal Bester and Eddie Welker:

Detonation1 makes small changes internal to Detonation, but the code which uses it (det.whatever) should remain unchanged.

However, it only addresses your first of your requests:
&lt;pre&gt;
&lt;code&gt;
function Detonation1(name,lat,lon,yld)
{
  var pow = (1/3), scale = Math.pow(yld,pow);

  // arbitrary values so I could test
  var conditions = { visibility: 1.0 };
  function makePoints (a,b)    { return [a,b]; }
  function thermDist  (a,b,c,d){ return (a*b*c*d); }
  function GLatLng    (lat,lon){ return [lat,lon]; }

  this.name = name;
  this.lon  = lon;
  this.lat  = lat;
  this.yld  = yld;
  this.gz   = new GLatLng(lat,lon);

  this.overpressure = {
    p30 : 0.108 * scale,
    p15 : 0.153 * scale,
    p10 : 0.185 * scale,
    p5 : 0.281 * scale,
    p1 : 0.725 * scale
  };
  this.psi30 = {
    radius: this.overpressure.p30,
    overlay : {
      points: makePoints(this.gz, pow)
    }
  };
  this.psi15 = {
    radius: this.overpressure.p15,
    overlay : {
      points: makePoints(this.gz, pow)
    }
  };
  // split this up so you don&#039;t do double thermDist calcs
  this.therm20 = {
    radius: thermDist(20,this.yld,pow,conditions.visibility)
  };
  this.therm20.overlay = {
      points: makePoints(this.gz, this.therm20.radius)
  };
  // ...and so on...
}
&lt;/code&gt;
&lt;/pre&gt;

Detonation2 causes somes changes externally (ie, &lt;code&gt;det.yield = 20&lt;/code&gt; becomes &lt;code&gt;det.yield(20)&lt;/code&gt; and similar)

However, you do get 1) automatic recalculation and 2) only calculated when needed.

&lt;pre&gt;
&lt;code&gt;
function Detonation2(name,lat,lon,yld)
{                  // D (this) is what gets returned as your instance
  var D   = this,  // D.some_name functions/properties available to instance
      pow = (1/3), // just a guess. saw 1/3 and 0.33 in a few places
      __s = {};   // data structure for &quot;private&quot; state info

  // arbitrary values so I could test
  var conditions = { visibility: 1.0 };
  function makePoints (a,b)    { return [a,b]; }
  function thermDist  (a,b,c,d){ return (a*b*c*d); }
  function GLatLng    (lat,lon){ return [lat,lon]; }

  // functions set values if passed arguments, else return current value
  // det.yield = 20 becomes det.yld(20)
  // and det.name = &#039;boom&#039; becomes det.name(&#039;boom&#039;)
  D.name  = function(n){ return __get_set(&#039;name&#039;, n); };
  D.lat   = function(l){ return __get_set(&#039;lat&#039;, l); };
  D.lon   = function(l){ return __get_set(&#039;lon&#039;, l); };
  D.yld   = function(y){ return __get_set(&#039;yld&#039;, y); };
  // D.gz = function(){ return __get_set(GLatLng(D.lat, D.lon)); }; // once
  D.gz    = function(){ return new GLatLng(D.lat, D.lon); };        // always new
  D.scale = function(){ return Math.pow(D.yld(), pow); };

  // base getter/setter function for D.name() and other convenience functions
  function __get_set(key,val){
    if (val){ __s[key] = val; } // set to val, if we get one
    return __s[key];            // return current (old or new) value of key
  };

  // set values based on constructor arguments
  D.name(name);
  D.lat(lat);
  D.lon(lon);
  D.yld(yld);

  D.overpressure = {
    p30: function(){ return 0.108 * D.scale(); },
    p15: function(){ return 0.153 * D.scale(); },
    p10: function(){ return 0.185 * D.scale(); },
    p5:  function(){ return 0.281 * D.scale(); },
    p1:  function(){ return 0.725 * D.scale(); }
  };

  D.psi30 = {
    radius: function(){ return D.overpressure.p30(); },
    overlay: {
      points: function(){
	return makePoints(D.gz(), D.overpressure.p30());
      }
    }
  };

  D.psi15 = {
    radius: function(){ return D.overpressure.p15(); },
    overlay: {
      points: function(){
	return makePoints(D.gz(), D.overpressure.p15());
      }
    }
  };

  // split D.therm20 assignment so you don&#039;t run thermDist() twice
  D.therm20 = {
    radius: function(){
      return thermDist(20, D.yld(), pow, conditions.visibility);
    }
  };

  D.therm20.overlay = {
    points: function(){
      return makePoints(D.gz(), D.therm20.radius()); // thermDist() results
    }
  };

  // ...and so on...

  return D; // D.properties are available to instance (result of new Detonation)
}
&lt;/code&gt;
&lt;/pre&gt;

You said you wanted something to poke at, so I went a bit heavy on the comments.

Just reading the example from Adam van den Hoven and it&#039;s along the lines of what I was going to suggest. Even after my refactoring, it&#039;s clear there are still patterns in the properties and function names (and their calculations) that could surely be reduced to a more abstract or basic formula.

Anyway, thanks for the mental exercise and, of course, your CSS and standards work.

P.S. &quot;pre&quot; tag doesn&#039;t work. Sorry, but I just can&#039;t go back and replace spaces w/ nbsb;]]></description>
		<content:encoded><![CDATA[<p>Piggy-backing on comments and code from Micheal Bester and Eddie Welker:</p>
<p>Detonation1 makes small changes internal to Detonation, but the code which uses it (det.whatever) should remain unchanged.</p>
<p>However, it only addresses your first of your requests:</p>
<pre>
<code>
function Detonation1(name,lat,lon,yld)
{
  var pow = (1/3), scale = Math.pow(yld,pow);

  // arbitrary values so I could test
  var conditions = { visibility: 1.0 };
  function makePoints (a,b)    { return [a,b]; }
  function thermDist  (a,b,c,d){ return (a*b*c*d); }
  function GLatLng    (lat,lon){ return [lat,lon]; }

  this.name = name;
  this.lon  = lon;
  this.lat  = lat;
  this.yld  = yld;
  this.gz   = new GLatLng(lat,lon);

  this.overpressure = {
    p30 : 0.108 * scale,
    p15 : 0.153 * scale,
    p10 : 0.185 * scale,
    p5 : 0.281 * scale,
    p1 : 0.725 * scale
  };
  this.psi30 = {
    radius: this.overpressure.p30,
    overlay : {
      points: makePoints(this.gz, pow)
    }
  };
  this.psi15 = {
    radius: this.overpressure.p15,
    overlay : {
      points: makePoints(this.gz, pow)
    }
  };
  // split this up so you don't do double thermDist calcs
  this.therm20 = {
    radius: thermDist(20,this.yld,pow,conditions.visibility)
  };
  this.therm20.overlay = {
      points: makePoints(this.gz, this.therm20.radius)
  };
  // ...and so on...
}
</code>
</pre>
<p>Detonation2 causes somes changes externally (ie, <code>det.yield = 20</code> becomes <code>det.yield(20)</code> and similar)</p>
<p>However, you do get 1) automatic recalculation and 2) only calculated when needed.</p>
<pre>
<code>
function Detonation2(name,lat,lon,yld)
{                  // D (this) is what gets returned as your instance
  var D   = this,  // D.some_name functions/properties available to instance
      pow = (1/3), // just a guess. saw 1/3 and 0.33 in a few places
      __s = {};   // data structure for "private" state info

  // arbitrary values so I could test
  var conditions = { visibility: 1.0 };
  function makePoints (a,b)    { return [a,b]; }
  function thermDist  (a,b,c,d){ return (a*b*c*d); }
  function GLatLng    (lat,lon){ return [lat,lon]; }

  // functions set values if passed arguments, else return current value
  // det.yield = 20 becomes det.yld(20)
  // and det.name = 'boom' becomes det.name('boom')
  D.name  = function(n){ return __get_set('name', n); };
  D.lat   = function(l){ return __get_set('lat', l); };
  D.lon   = function(l){ return __get_set('lon', l); };
  D.yld   = function(y){ return __get_set('yld', y); };
  // D.gz = function(){ return __get_set(GLatLng(D.lat, D.lon)); }; // once
  D.gz    = function(){ return new GLatLng(D.lat, D.lon); };        // always new
  D.scale = function(){ return Math.pow(D.yld(), pow); };

  // base getter/setter function for D.name() and other convenience functions
  function __get_set(key,val){
    if (val){ __s[key] = val; } // set to val, if we get one
    return __s[key];            // return current (old or new) value of key
  };

  // set values based on constructor arguments
  D.name(name);
  D.lat(lat);
  D.lon(lon);
  D.yld(yld);

  D.overpressure = {
    p30: function(){ return 0.108 * D.scale(); },
    p15: function(){ return 0.153 * D.scale(); },
    p10: function(){ return 0.185 * D.scale(); },
    p5:  function(){ return 0.281 * D.scale(); },
    p1:  function(){ return 0.725 * D.scale(); }
  };

  D.psi30 = {
    radius: function(){ return D.overpressure.p30(); },
    overlay: {
      points: function(){
	return makePoints(D.gz(), D.overpressure.p30());
      }
    }
  };

  D.psi15 = {
    radius: function(){ return D.overpressure.p15(); },
    overlay: {
      points: function(){
	return makePoints(D.gz(), D.overpressure.p15());
      }
    }
  };

  // split D.therm20 assignment so you don't run thermDist() twice
  D.therm20 = {
    radius: function(){
      return thermDist(20, D.yld(), pow, conditions.visibility);
    }
  };

  D.therm20.overlay = {
    points: function(){
      return makePoints(D.gz(), D.therm20.radius()); // thermDist() results
    }
  };

  // ...and so on...

  return D; // D.properties are available to instance (result of new Detonation)
}
</code>
</pre>
<p>You said you wanted something to poke at, so I went a bit heavy on the comments.</p>
<p>Just reading the example from Adam van den Hoven and it&#8217;s along the lines of what I was going to suggest. Even after my refactoring, it&#8217;s clear there are still patterns in the properties and function names (and their calculations) that could surely be reduced to a more abstract or basic formula.</p>
<p>Anyway, thanks for the mental exercise and, of course, your CSS and standards work.</p>
<p>P.S. &#8220;pre&#8221; tag doesn&#8217;t work. Sorry, but I just can&#8217;t go back and replace spaces w/ nbsb;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Meyer</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436829</link>
		<dc:creator>Eric Meyer</dc:creator>
		<pubDate>Sat, 17 Jan 2009 02:10:53 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436829</guid>
		<description><![CDATA[Wow!  You all are 125% awesome, with a side order of fantastic.  When I finally decide to give HYDEsim a complete overhaul, I know who to e-mail.  Thank you!

(Also, I think &lt;code&gt;pre&lt;/code&gt; is allowed in comments even if it isn&#039;t listed as accepted.  Someone try it and we&#039;ll see.  If not, sorry!  I&#039;ll get it on the list.)]]></description>
		<content:encoded><![CDATA[<p>Wow!  You all are 125% awesome, with a side order of fantastic.  When I finally decide to give HYDEsim a complete overhaul, I know who to e-mail.  Thank you!</p>
<p>(Also, I think <code>pre</code> is allowed in comments even if it isn&#8217;t listed as accepted.  Someone try it and we&#8217;ll see.  If not, sorry!  I&#8217;ll get it on the list.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam van den Hoven</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436769</link>
		<dc:creator>Adam van den Hoven</dc:creator>
		<pubDate>Fri, 16 Jan 2009 22:19:37 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436769</guid>
		<description><![CDATA[Here&#039;s my kick at the can. I&#039;ve only rewritten what it given in the example, I assume that more can be added later.:

&lt;pre&gt;
&lt;code&gt;window.Detination&#160;=&#160;(function(){
&#160;&#160;function&#160;makeOverPressure(scale){
&#160;&#160;&#160;&#160;var&#160;OP_MULT&#160;=&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;30&#160;:&#160;0.108,
&#160;&#160;&#160;&#160;&#160;&#160;15&#160;:&#160;0.153,
&#160;&#160;&#160;&#160;&#160;&#160;10&#160;:&#160;0.185,
&#160;&#160;&#160;&#160;&#160;&#160;5&#160;:&#160;0.281,
&#160;&#160;&#160;&#160;&#160;&#160;1&#160;:&#160;0.725,
&#160;&#160;&#160;&#160;},&#160;res&#160;=&#160;{};
&#160;&#160;&#160;&#160;for(&#160;mult&#160;in&#160;OP_MULT&#160;){
&#160;&#160;&#160;&#160;&#160;&#160;res[mult]&#160;=&#160;OP_MULT[mult]&#160;*&#160;scale;
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;return&#160;res;
&#160;&#160;}
&#160;&#160;function&#160;makeThermalDistances(&#160;yield,&#160;visibility&#160;){
&#160;&#160;&#160;&#160;var&#160;TD_MULT&#160;=&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;20&#160;:&#160;0.33
&#160;&#160;&#160;&#160;},&#160;res&#160;=&#160;{};
&#160;&#160;&#160;&#160;for(&#160;mult&#160;in&#160;TD_MULT&#160;){
&#160;&#160;&#160;&#160;&#160;&#160;res[mult]&#160;=&#160;thermDist(&#160;mult,&#160;yield,&#160;TD_MULT[mult],&#160;visibility);
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;return&#160;res;
&#160;&#160;}
&#160;&#160;function&#160;makeOverlays(distance,&#160;center)&#160;{
&#160;&#160;&#160;&#160;var&#160;res&#160;=&#160;{};
&#160;&#160;&#160;&#160;for(&#160;dist&#160;in&#160;distance&#160;){
&#160;&#160;&#160;&#160;&#160;&#160;res[dist]&#160;=&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;radius:&#160;distance[dist],
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;overlay{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;points:&#160;makePoints(center,&#160;distance[dist])
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;return&#160;res;
&#160;&#160;}
&#160;&#160;return&#160;function&#160;(name,lat,lon,yield){
&#160;&#160;&#160;&#160;var&#160;scale&#160;=&#160;Math.pow(yield,1/3),
&#160;&#160;&#160;&#160;gz&#160;=&#160;new&#160;GLatLng(lat,lon),
&#160;&#160;&#160;&#160;op&#160;=&#160;makeOverPressure(scale),
&#160;&#160;&#160;&#160;td&#160;=&#160;makeThermalDistances(&#160;yield,&#160;conditions.visibility);
&#160;&#160;&#160;&#160;return&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;psi:&#160;makeDistances(&#160;op&#160;),
&#160;&#160;&#160;&#160;&#160;&#160;thermal:&#160;makeDistances(&#160;td&#160;)
&#160;&#160;&#160;&#160;}
&#160;&#160;}
}){};
&lt;/code&gt;
&lt;/pre&gt;

Gaak! nbsp to get the indenting. 

First of all, Detination uses a variation on Crockfords power constructor so don&#039;t call it with new (but it should work regardless). Second the object it creates has two members, psi and therm. These each have a number of numerically identified members each of which contain the radius and points. You would do the following:

&lt;pre&gt;
&lt;code&gt;
foo = Detenation( &#039;example&#039;, 50, 120, 200 );
foo.psi[10].radius;
foo.psi[10].overlay.points;
foo.therm[20].overlay.points;
&lt;/code&gt;
&lt;/pre&gt;

I&#039;ll leave it up to the reader to add the other useful bits in (like the name, yield, etc). 

This has a number of advantages. First of all the global scope is kept pristine. Second, those things that are fixed (the different PSI levels, for example) and the functions that use them are only created once. Third its easy to add levels, simply add members to the OP_MULT and TD_MULT constants.]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s my kick at the can. I&#8217;ve only rewritten what it given in the example, I assume that more can be added later.:</p>
<pre>
<code>window.Detination&nbsp;=&nbsp;(function(){
&nbsp;&nbsp;function&nbsp;makeOverPressure(scale){
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;OP_MULT&nbsp;=&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30&nbsp;:&nbsp;0.108,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15&nbsp;:&nbsp;0.153,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;:&nbsp;0.185,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;:&nbsp;0.281,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;:&nbsp;0.725,
&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;res&nbsp;=&nbsp;{};
&nbsp;&nbsp;&nbsp;&nbsp;for(&nbsp;mult&nbsp;in&nbsp;OP_MULT&nbsp;){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res[mult]&nbsp;=&nbsp;OP_MULT[mult]&nbsp;*&nbsp;scale;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;res;
&nbsp;&nbsp;}
&nbsp;&nbsp;function&nbsp;makeThermalDistances(&nbsp;yield,&nbsp;visibility&nbsp;){
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;TD_MULT&nbsp;=&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;:&nbsp;0.33
&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;res&nbsp;=&nbsp;{};
&nbsp;&nbsp;&nbsp;&nbsp;for(&nbsp;mult&nbsp;in&nbsp;TD_MULT&nbsp;){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res[mult]&nbsp;=&nbsp;thermDist(&nbsp;mult,&nbsp;yield,&nbsp;TD_MULT[mult],&nbsp;visibility);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;res;
&nbsp;&nbsp;}
&nbsp;&nbsp;function&nbsp;makeOverlays(distance,&nbsp;center)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;res&nbsp;=&nbsp;{};
&nbsp;&nbsp;&nbsp;&nbsp;for(&nbsp;dist&nbsp;in&nbsp;distance&nbsp;){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res[dist]&nbsp;=&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius:&nbsp;distance[dist],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;points:&nbsp;makePoints(center,&nbsp;distance[dist])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;res;
&nbsp;&nbsp;}
&nbsp;&nbsp;return&nbsp;function&nbsp;(name,lat,lon,yield){
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;scale&nbsp;=&nbsp;Math.pow(yield,1/3),
&nbsp;&nbsp;&nbsp;&nbsp;gz&nbsp;=&nbsp;new&nbsp;GLatLng(lat,lon),
&nbsp;&nbsp;&nbsp;&nbsp;op&nbsp;=&nbsp;makeOverPressure(scale),
&nbsp;&nbsp;&nbsp;&nbsp;td&nbsp;=&nbsp;makeThermalDistances(&nbsp;yield,&nbsp;conditions.visibility);
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;psi:&nbsp;makeDistances(&nbsp;op&nbsp;),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thermal:&nbsp;makeDistances(&nbsp;td&nbsp;)
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
}){};
</code>
</pre>
<p>Gaak! nbsp to get the indenting. </p>
<p>First of all, Detination uses a variation on Crockfords power constructor so don&#8217;t call it with new (but it should work regardless). Second the object it creates has two members, psi and therm. These each have a number of numerically identified members each of which contain the radius and points. You would do the following:</p>
<pre>
<code>
foo = Detenation( 'example', 50, 120, 200 );
foo.psi[10].radius;
foo.psi[10].overlay.points;
foo.therm[20].overlay.points;
</code>
</pre>
<p>I&#8217;ll leave it up to the reader to add the other useful bits in (like the name, yield, etc). </p>
<p>This has a number of advantages. First of all the global scope is kept pristine. Second, those things that are fixed (the different PSI levels, for example) and the functions that use them are only created once. Third its easy to add levels, simply add members to the OP_MULT and TD_MULT constants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Mills</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436705</link>
		<dc:creator>Anthony Mills</dc:creator>
		<pubDate>Fri, 16 Jan 2009 17:59:32 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436705</guid>
		<description><![CDATA[Oops, I mean &lt;code&gt;this.recalculate()&lt;/code&gt;, of course. Not just &lt;code&gt;recalculate()&lt;/code&gt;.]]></description>
		<content:encoded><![CDATA[<p>Oops, I mean <code>this.recalculate()</code>, of course. Not just <code>recalculate()</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: VanillaMozilla</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436693</link>
		<dc:creator>VanillaMozilla</dc:creator>
		<pubDate>Fri, 16 Jan 2009 17:21:27 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436693</guid>
		<description><![CDATA[&quot;Even though it turned out that there is no simple solution for the math problem I posted....&quot;

But there is a simple solution:  the value of D that satisfies the equation.  What can be simpler than that?

Maybe a few comments at this point will make such problems easier in the future.

There is a simple numerical solution but no ALGEBRAIC solution.  And your brute-force method is exactly how such equations are solved, that is to say, by numerical approximation.  Now there are some mathematical tricks to improve the efficiency of arriving at a solution.  Two simple methods come to mind.

1. g(D) = Q-f(D).  At what value of D does g(D) = 0?  Trial and error. (Extra points if you can efficiently estimate the next guess.  The pros use the slope g&#039;(D) to improve their aim.  And if you can&#039;t calculate the slope algebraically, you can estimate it numerically.)

2. D approximately = f(D).  At what point does D=f(D)?  This is a helpful trick that you can use sometimes.  If you know the approximate range of values of the various parameters, you may be able to rewrite the equation in a way such that f(D) does not depend much on D.  Then you can iterate and get the value in a hurry.

In your previous example, if D/V &lt;&lt; 1 and both are positive, then as a first approximation maybe you can ignore the exponential.  Then D^2=3.07FY(1+1.4ED/V)/Q, where E is that nasty exponential.  You can solve that for D algebraically to get your approximation.  Make a first guess, find the value of E, plug all the numbers into the equation to get your next guess.  Plug that value back into E to get the next guess.  Repeat until satisfied.  If D/V is not sufficiently small, it might not work, as you will find out very quickly.

In both cases, you have to watch out for the special cases Q=0 and V=0.  (The function is undefined at those values!)  If you are iterating and encounter those values (or cross those values), then obviously there is trouble.]]></description>
		<content:encoded><![CDATA[<p>&#8220;Even though it turned out that there is no simple solution for the math problem I posted&#8230;.&#8221;</p>
<p>But there is a simple solution:  the value of D that satisfies the equation.  What can be simpler than that?</p>
<p>Maybe a few comments at this point will make such problems easier in the future.</p>
<p>There is a simple numerical solution but no ALGEBRAIC solution.  And your brute-force method is exactly how such equations are solved, that is to say, by numerical approximation.  Now there are some mathematical tricks to improve the efficiency of arriving at a solution.  Two simple methods come to mind.</p>
<p>1. g(D) = Q-f(D).  At what value of D does g(D) = 0?  Trial and error. (Extra points if you can efficiently estimate the next guess.  The pros use the slope g&#8217;(D) to improve their aim.  And if you can&#8217;t calculate the slope algebraically, you can estimate it numerically.)</p>
<p>2. D approximately = f(D).  At what point does D=f(D)?  This is a helpful trick that you can use sometimes.  If you know the approximate range of values of the various parameters, you may be able to rewrite the equation in a way such that f(D) does not depend much on D.  Then you can iterate and get the value in a hurry.</p>
<p>In your previous example, if D/V &lt;&lt; 1 and both are positive, then as a first approximation maybe you can ignore the exponential.  Then D^2=3.07FY(1+1.4ED/V)/Q, where E is that nasty exponential.  You can solve that for D algebraically to get your approximation.  Make a first guess, find the value of E, plug all the numbers into the equation to get your next guess.  Plug that value back into E to get the next guess.  Repeat until satisfied.  If D/V is not sufficiently small, it might not work, as you will find out very quickly.</p>
<p>In both cases, you have to watch out for the special cases Q=0 and V=0.  (The function is undefined at those values!)  If you are iterating and encounter those values (or cross those values), then obviously there is trouble.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Mills</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436687</link>
		<dc:creator>Anthony Mills</dc:creator>
		<pubDate>Fri, 16 Jan 2009 17:11:22 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436687</guid>
		<description><![CDATA[Here&#039;s a version of the code with underlines for indents:

&lt;code&gt;function Detonation(name, lat, lon, yield) {
____this.name = name;
____this.lat = lat;
____this.lon = lon;
____this.gz = new GLatLng(lat, lon);
____this.yield = yield;
____recalculate();  // cheaper than doing setThis(); setThat(); all of which will call recalculate()
}
Detonation.prototype.setYield = function (yield) {
____this.yield = yield;
____recalculate();
};
Detonation.prototype.recalculate = function () {
____function makeDestruction() {
________var result = {};
________for (var i = 0; i &lt; arguments.length; i++) {
____________var radius = arguments[i].factor * scale;
____________result[arguments[i].psi] = {
________________radius: radius,
________________overlay: { points: makePoints(this.gz, radius) }
____________};
________}
________return result;
____}
____function makeTemperature() {
________var result = {};
________for (var i = 0; i &lt; arguments.length; i++) {
____________var radius = thermDist(arguments[i].celsius, this.yield, arguments[i].factor, conditions.visibility);
____________result[arguments[i].celsius] = {
________________radius: radius,
________________overlay: { points: makePoints(this.gz, radius) }
____________}
________}
________return result;
____}
____var scale = Math.pow(yield, 1/3);
____this.destructionAtPsi = makeDestruction.call(this,  // need &quot;.call(this,&quot; to preserve &quot;this&quot; in inner function
________{psi: 30, factor: 0.108},
________{psi: 15, factor: 0.153},
________{psi: 10, factor: 0.185},
________{psi: 5, factor: 0.281},
________{psi: 1, factor: 0.725}
____);
____this.temperature = makeTemperature.call(this,
________{celsius: 20, factor: 0.33},
________...
____);
};&lt;/code&gt;

Can we please get a markup engine that DOESN&#039;T SCREW UP CODE IN CODE TAGS AAAAAAAAAAAARGH.

Sorry, just had to vent.]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s a version of the code with underlines for indents:</p>
<p><code>function Detonation(name, lat, lon, yield) {<br />
____this.name = name;<br />
____this.lat = lat;<br />
____this.lon = lon;<br />
____this.gz = new GLatLng(lat, lon);<br />
____this.yield = yield;<br />
____recalculate();  // cheaper than doing setThis(); setThat(); all of which will call recalculate()<br />
}<br />
Detonation.prototype.setYield = function (yield) {<br />
____this.yield = yield;<br />
____recalculate();<br />
};<br />
Detonation.prototype.recalculate = function () {<br />
____function makeDestruction() {<br />
________var result = {};<br />
________for (var i = 0; i &lt; arguments.length; i++) {<br />
____________var radius = arguments[i].factor * scale;<br />
____________result[arguments[i].psi] = {<br />
________________radius: radius,<br />
________________overlay: { points: makePoints(this.gz, radius) }<br />
____________};<br />
________}<br />
________return result;<br />
____}<br />
____function makeTemperature() {<br />
________var result = {};<br />
________for (var i = 0; i &lt; arguments.length; i++) {<br />
____________var radius = thermDist(arguments[i].celsius, this.yield, arguments[i].factor, conditions.visibility);<br />
____________result[arguments[i].celsius] = {<br />
________________radius: radius,<br />
________________overlay: { points: makePoints(this.gz, radius) }<br />
____________}<br />
________}<br />
________return result;<br />
____}<br />
____var scale = Math.pow(yield, 1/3);<br />
____this.destructionAtPsi = makeDestruction.call(this,  // need ".call(this," to preserve "this" in inner function<br />
________{psi: 30, factor: 0.108},<br />
________{psi: 15, factor: 0.153},<br />
________{psi: 10, factor: 0.185},<br />
________{psi: 5, factor: 0.281},<br />
________{psi: 1, factor: 0.725}<br />
____);<br />
____this.temperature = makeTemperature.call(this,<br />
________{celsius: 20, factor: 0.33},<br />
________...<br />
____);<br />
};</code></p>
<p>Can we please get a markup engine that DOESN&#8217;T SCREW UP CODE IN CODE TAGS AAAAAAAAAAAARGH.</p>
<p>Sorry, just had to vent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Mills</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436685</link>
		<dc:creator>Anthony Mills</dc:creator>
		<pubDate>Fri, 16 Jan 2009 17:08:59 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436685</guid>
		<description><![CDATA[Sorry for the underlines but it just does not format correctly otherwise. Argh!

Anyway, the idea here is you use inner functions to calculate the main bits. When you want to access stuff, it&#039;s like:
&lt;pre&gt;
&lt;code&gt;var det = new Detonation(&quot;blah&quot;, 0, 0, 42);
var radius = det.destructionAtPsi[30].radius;

// iterate through overpressure values
for (var overpressure in det.destructionAtPsi) {
    var overlay = det.destructionAtPsi[overpressure].overlay;
}&lt;/code&gt;
&lt;/pre&gt;

This way you only define your PSI values and other factors once.

Anyway, the code is:

&lt;pre&gt;
&lt;code&gt;function Detonation(name, lat, lon, yield) {
    this.name = name;
    this.lat = lat;
    this.lon = lon;
    this.gz = new GLatLng(lat, lon);
    this.yield = yield;
    recalculate();  // cheaper than doing setThis(); setThat(); all of which will call recalculate()
}

Detonation.prototype.setYield = function (yield) {
    this.yield = yield;
    recalculate();
};

Detonation.prototype.recalculate = function () {

    function makeDestruction() {
        var result = {};
        for (var i = 0; i &lt; arguments.length; i++) {
            var radius = arguments[i].factor * scale;
            result[arguments[i].psi] = {
                radius: radius,
                overlay: { points: makePoints(this.gz, radius) }
            };
        }
        return result;
    }

    function makeTemperature() {
        var result = {};
        for (var i = 0; i &lt; arguments.length; i++) {
            var radius = thermDist(arguments[i].celsius, this.yield, arguments[i].factor, conditions.visibility);
            result[arguments[i].celsius] = {
                radius: radius,
                overlay: { points: makePoints(this.gz, radius) }
            }
        }
        return result;
    }

    var scale = Math.pow(yield, 1/3);
    this.destructionAtPsi = makeDestruction.call(this,  // need &quot;.call(this,&quot; to preserve &quot;this&quot; in inner function
        {psi: 30, factor: 0.108},
        {psi: 15, factor: 0.153},
        {psi: 10, factor: 0.185},
        {psi: 5, factor: 0.281},
        {psi: 1, factor: 0.725}
    );
    this.temperature = makeTemperature.call(this,
        {celsius: 20, factor: 0.33},
        ...
    );
};&lt;/code&gt;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Sorry for the underlines but it just does not format correctly otherwise. Argh!</p>
<p>Anyway, the idea here is you use inner functions to calculate the main bits. When you want to access stuff, it&#8217;s like:</p>
<pre>
<code>var det = new Detonation("blah", 0, 0, 42);
var radius = det.destructionAtPsi[30].radius;

// iterate through overpressure values
for (var overpressure in det.destructionAtPsi) {
    var overlay = det.destructionAtPsi[overpressure].overlay;
}</code>
</pre>
<p>This way you only define your PSI values and other factors once.</p>
<p>Anyway, the code is:</p>
<pre>
<code>function Detonation(name, lat, lon, yield) {
    this.name = name;
    this.lat = lat;
    this.lon = lon;
    this.gz = new GLatLng(lat, lon);
    this.yield = yield;
    recalculate();  // cheaper than doing setThis(); setThat(); all of which will call recalculate()
}

Detonation.prototype.setYield = function (yield) {
    this.yield = yield;
    recalculate();
};

Detonation.prototype.recalculate = function () {

    function makeDestruction() {
        var result = {};
        for (var i = 0; i &lt; arguments.length; i++) {
            var radius = arguments[i].factor * scale;
            result[arguments[i].psi] = {
                radius: radius,
                overlay: { points: makePoints(this.gz, radius) }
            };
        }
        return result;
    }

    function makeTemperature() {
        var result = {};
        for (var i = 0; i &lt; arguments.length; i++) {
            var radius = thermDist(arguments[i].celsius, this.yield, arguments[i].factor, conditions.visibility);
            result[arguments[i].celsius] = {
                radius: radius,
                overlay: { points: makePoints(this.gz, radius) }
            }
        }
        return result;
    }

    var scale = Math.pow(yield, 1/3);
    this.destructionAtPsi = makeDestruction.call(this,  // need ".call(this," to preserve "this" in inner function
        {psi: 30, factor: 0.108},
        {psi: 15, factor: 0.153},
        {psi: 10, factor: 0.185},
        {psi: 5, factor: 0.281},
        {psi: 1, factor: 0.725}
    );
    this.temperature = makeTemperature.call(this,
        {celsius: 20, factor: 0.33},
        ...
    );
};</code>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich Waters</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436680</link>
		<dc:creator>Rich Waters</dc:creator>
		<pubDate>Fri, 16 Jan 2009 16:39:26 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436680</guid>
		<description><![CDATA[Not really knowing the context of this code makes things a little tougher, but I would probably do something along these lines:
&lt;pre&gt;
&lt;code&gt;
function Detonation(name, lat, lon, yield) {
	var gz = new GLatLng(lat, lon);
	this.name = name;
	this.lon = lon;
	this.lat = lat;
	this.gz = gz;
	this.setYield(yield);
}

Detonation.prototype = {
	pressures: {
		p30: 0.108,
		p15: 0.153,
		p10: 0.185,
		p5: 0.281,
		p1: 0.725
	},
	setYield: function(yld) {
		this.yield = yld;
		this.scale = Math.pow(yld, 1 / 3);
	},
	overpressure: function(psi) {
		return this.pressures[psi] * this.scale;
	},
	getPressure: function(pres) {
		var p = this.overpressure(pres);
		return {
			radius: p,
			overlay: {
				points: makePoints(this.gz, p)
			}
		}
	},
	psi30: function() {
		return this.getPressure(&#039;p30&#039;);
	},
	psi15: function() {
		return this.getPressure(&#039;p15&#039;);
	},
	therm20: function() {
		return {
			radius: thermDist(20, this.yield, 0.33, conditions.visibility),
			overlay: {
				points: makePoints(this.gz, thermDist(20, this.yield, 0.33, conditions.visibility))
			}
		}
	}
}
&lt;/code&gt;
&lt;/pre&gt;

Sorry if the formatting didn&#039;t come through, I tried a few tags and combinations and couldn&#039;t get it to look right in the preview.]]></description>
		<content:encoded><![CDATA[<p>Not really knowing the context of this code makes things a little tougher, but I would probably do something along these lines:</p>
<pre>
<code>
function Detonation(name, lat, lon, yield) {
	var gz = new GLatLng(lat, lon);
	this.name = name;
	this.lon = lon;
	this.lat = lat;
	this.gz = gz;
	this.setYield(yield);
}

Detonation.prototype = {
	pressures: {
		p30: 0.108,
		p15: 0.153,
		p10: 0.185,
		p5: 0.281,
		p1: 0.725
	},
	setYield: function(yld) {
		this.yield = yld;
		this.scale = Math.pow(yld, 1 / 3);
	},
	overpressure: function(psi) {
		return this.pressures[psi] * this.scale;
	},
	getPressure: function(pres) {
		var p = this.overpressure(pres);
		return {
			radius: p,
			overlay: {
				points: makePoints(this.gz, p)
			}
		}
	},
	psi30: function() {
		return this.getPressure('p30');
	},
	psi15: function() {
		return this.getPressure('p15');
	},
	therm20: function() {
		return {
			radius: thermDist(20, this.yield, 0.33, conditions.visibility),
			overlay: {
				points: makePoints(this.gz, thermDist(20, this.yield, 0.33, conditions.visibility))
			}
		}
	}
}
</code>
</pre>
<p>Sorry if the formatting didn&#8217;t come through, I tried a few tags and combinations and couldn&#8217;t get it to look right in the preview.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kent Brewster</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436677</link>
		<dc:creator>Kent Brewster</dc:creator>
		<pubDate>Fri, 16 Jan 2009 16:36:42 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436677</guid>
		<description><![CDATA[Right there with you, Eric.  Any theoretical discussion of programming quickly turns into the last line of Dr. Seuss&#039;s Fox In Socks for me. (From faulty memory:  when the tweedle beetles battle in a bottle with their paddles, and the bottle&#039;s on a poodle and the poodle&#039;s eating noodles, THIS is what we call a muddle puddle tweedle beetle poodle noodle bottle paddle battle.  Or something like that.)]]></description>
		<content:encoded><![CDATA[<p>Right there with you, Eric.  Any theoretical discussion of programming quickly turns into the last line of Dr. Seuss&#8217;s Fox In Socks for me. (From faulty memory:  when the tweedle beetles battle in a bottle with their paddles, and the bottle&#8217;s on a poodle and the poodle&#8217;s eating noodles, THIS is what we call a muddle puddle tweedle beetle poodle noodle bottle paddle battle.  Or something like that.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Bester</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436676</link>
		<dc:creator>Michael Bester</dc:creator>
		<pubDate>Fri, 16 Jan 2009 16:36:14 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436676</guid>
		<description><![CDATA[Along the lines of what &lt;a href=&quot;#comment-436643&quot; rel=&quot;nofollow&quot;&gt;Eddie Welker&lt;/a&gt; suggested, instead of setting all the values when you instantiate the Detonation object, you calculate individual values as needed. This basically amounts to wrapping functions around everything. This code is untested, but should get you close:

&lt;pre&gt;
&lt;code&gt;
function Detonation(name,lat,lon,yield) {

	this.name = name;
	this.lon = lon;
	this.lat = lat;
	this.yield = yield;

	this.getScale = function() {
		return Math.pow(this.yield, 1/3);
	};

	this.getGZ = function() {
		return new GLatLng(this.lat, this.lon);
	};

	this.overpressure = {
		p30 : function() {
			return 0.108 * this.getScale();
		},
		p15 : function() {
			return 0.153 * this.getScale();
		},
		p10 : function() {
			return 0.185 * this.getScale();
		},
		p5 : function() {
			return 0.281 * this.getScale();
		},
		p1 : function() {
			return 0.725 * this.getScale();
		}
	};

	this.psi30 = {
		radius: function() {
			return this.overpressure.p30()
		},
		overlay : {
			points: function() {
				return makePoints(this.getGZ(), this.overpressure.p30());
			}
		}
	};

	this.psi15 = {
		radius: function() {
			return this.overpressure.p15()
		},
		overlay : {
			points: function() {
				return makePoints(this.getGZ(), this.overpressure.p15());
			}
		}
	};

	this.therm20 = {
		radius: function() {
			return thermDist(20, this.yield, 0.33, conditions.visibility),
		},
		overlay : {
			points: function() {
				return makePoints(
					this.gz,
					thermDist(20, this.yield, 0.33, conditions.visibility)
				)
			}
		};
		// ...and so on...
	}
&lt;/code&gt;
&lt;/pre&gt;

This also takes care of issue #1 in that you set your radii calculations once and refer to them as needed.]]></description>
		<content:encoded><![CDATA[<p>Along the lines of what <a href="#comment-436643" rel="nofollow">Eddie Welker</a> suggested, instead of setting all the values when you instantiate the Detonation object, you calculate individual values as needed. This basically amounts to wrapping functions around everything. This code is untested, but should get you close:</p>
<pre>
<code>
function Detonation(name,lat,lon,yield) {

	this.name = name;
	this.lon = lon;
	this.lat = lat;
	this.yield = yield;

	this.getScale = function() {
		return Math.pow(this.yield, 1/3);
	};

	this.getGZ = function() {
		return new GLatLng(this.lat, this.lon);
	};

	this.overpressure = {
		p30 : function() {
			return 0.108 * this.getScale();
		},
		p15 : function() {
			return 0.153 * this.getScale();
		},
		p10 : function() {
			return 0.185 * this.getScale();
		},
		p5 : function() {
			return 0.281 * this.getScale();
		},
		p1 : function() {
			return 0.725 * this.getScale();
		}
	};

	this.psi30 = {
		radius: function() {
			return this.overpressure.p30()
		},
		overlay : {
			points: function() {
				return makePoints(this.getGZ(), this.overpressure.p30());
			}
		}
	};

	this.psi15 = {
		radius: function() {
			return this.overpressure.p15()
		},
		overlay : {
			points: function() {
				return makePoints(this.getGZ(), this.overpressure.p15());
			}
		}
	};

	this.therm20 = {
		radius: function() {
			return thermDist(20, this.yield, 0.33, conditions.visibility),
		},
		overlay : {
			points: function() {
				return makePoints(
					this.gz,
					thermDist(20, this.yield, 0.33, conditions.visibility)
				)
			}
		};
		// ...and so on...
	}
</code>
</pre>
<p>This also takes care of issue #1 in that you set your radii calculations once and refer to them as needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan Seiz</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436673</link>
		<dc:creator>Stefan Seiz</dc:creator>
		<pubDate>Fri, 16 Jan 2009 16:21:59 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436673</guid>
		<description><![CDATA[&lt;cite&gt;Well, I&quot;d instantiate a binding function, thereby avoiding the double recursion closure bug that you&quot;ve got because you failed to globally initialise the object prototype.&lt;/cite&gt;

I assume this is exactly the kind of comment Eric loves to hear (no offense Bruce i appreciate your comment nonetheless). I am in the same shoes as Eric and appreciate Eric&#039;s calls for help very much. So much to learn here if you are able to understand the comments. Great!]]></description>
		<content:encoded><![CDATA[<p><cite>Well, I&#8221;d instantiate a binding function, thereby avoiding the double recursion closure bug that you&#8221;ve got because you failed to globally initialise the object prototype.</cite></p>
<p>I assume this is exactly the kind of comment Eric loves to hear (no offense Bruce i appreciate your comment nonetheless). I am in the same shoes as Eric and appreciate Eric&#8217;s calls for help very much. So much to learn here if you are able to understand the comments. Great!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bruce</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436667</link>
		<dc:creator>bruce</dc:creator>
		<pubDate>Fri, 16 Jan 2009 15:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436667</guid>
		<description><![CDATA[Well, I&#039;d instantiate a  binding function, thereby avoiding the double recursion closure bug that you&#039;ve got because you failed to globally initialise the object prototype.

Or I&#039;d hit it with a hammer and curse.]]></description>
		<content:encoded><![CDATA[<p>Well, I&#8217;d instantiate a  binding function, thereby avoiding the double recursion closure bug that you&#8217;ve got because you failed to globally initialise the object prototype.</p>
<p>Or I&#8217;d hit it with a hammer and curse.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul D. Waite</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436666</link>
		<dc:creator>Paul D. Waite</dc:creator>
		<pubDate>Fri, 16 Jan 2009 15:49:32 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436666</guid>
		<description><![CDATA[If this problem doesn&quot;t get solved here, you could try posting it on &lt;a href=&quot;http://www.stackoverflow.com/&quot; rel=&quot;nofollow&quot;&gt;Stack Overflow&lt;/a&gt;.]]></description>
		<content:encoded><![CDATA[<p>If this problem doesn&#8221;t get solved here, you could try posting it on <a href="http://www.stackoverflow.com/" rel="nofollow">Stack Overflow</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Welker</title>
		<link>http://meyerweb.com/eric/thoughts/2009/01/16/seeking-javascript-help/#comment-436643</link>
		<dc:creator>Eddie Welker</dc:creator>
		<pubDate>Fri, 16 Jan 2009 14:32:50 +0000</pubDate>
		<guid isPermaLink="false">http://meyerweb.com/?p=1000#comment-436643</guid>
		<description><![CDATA[This may not work... so you&#039;ve got a template there for creating a Detonation object.  But it&#039;s important in what context you create that object, so this may not be right.

1) If you&#039;re essentially calculating the radius measurements when you&#039;re creating the this.overpressure object, you should be able to refer specifically to the &quot;this.overpressure.p30&quot;.  So in this.psi30, you can simply write &quot;radius: this.overpressure.p30&quot;.  You can do the same 2 lines down, specifying &quot;points: makePoints(this.gz, this.overpressure.p30)&quot;.  As you say, if you&#039;ve referred to it once, you don&#039;t need to recalculate.

2) For this, you can&#039;t really restructure your existing code to do it, you&#039;ll need to change the structure of the Detonation obj.  Here&#039;s why....  As of the moment, when you create your object, you&#039;re doing all of these calculations and wiring the results of the calculations into your Detonation object.  To dynamically recalculate (like if you were to set a new yield), you&#039;d have to create a new function that does all of the (needed) recalculations again.  At this point, you&#039;d then want to rewrite your code so when you create a new object, you also call this new function (so you don&#039;t have 2 pieces of code that do the same thing, in multiple places.. it&#039;s easier to maintain, etc.).

However, a better solution (though you may not be able to... I&#039;m only looking at an abbreviated version), would be to simply store the 4 or so parameters you pass to the Detonation object (name, lat, lon, yield). You then write functions that automatically create these values for you &lt;i&gt;only when you ask for them&lt;/i&gt;.  That way, you can set a new yield, and not waste any time recalculating then... you could wait to recalculate the values only when you need to.  

The ideal solution is probably somewhere inbetween.... where you store the 4 parameters, as well creating a function to re-calculate the radius measurements each time... since you use those so often, it&#039;d be more efficient (as you said in #1) to calculate them just once.

I know you said you&#039;d like to look at code, and this is just a high-level overview, but let us know what kinda changes you can make, and we can try to get to code.]]></description>
		<content:encoded><![CDATA[<p>This may not work&#8230; so you&#8217;ve got a template there for creating a Detonation object.  But it&#8217;s important in what context you create that object, so this may not be right.</p>
<p>1) If you&#8217;re essentially calculating the radius measurements when you&#8217;re creating the this.overpressure object, you should be able to refer specifically to the &#8220;this.overpressure.p30&#8243;.  So in this.psi30, you can simply write &#8220;radius: this.overpressure.p30&#8243;.  You can do the same 2 lines down, specifying &#8220;points: makePoints(this.gz, this.overpressure.p30)&#8221;.  As you say, if you&#8217;ve referred to it once, you don&#8217;t need to recalculate.</p>
<p>2) For this, you can&#8217;t really restructure your existing code to do it, you&#8217;ll need to change the structure of the Detonation obj.  Here&#8217;s why&#8230;.  As of the moment, when you create your object, you&#8217;re doing all of these calculations and wiring the results of the calculations into your Detonation object.  To dynamically recalculate (like if you were to set a new yield), you&#8217;d have to create a new function that does all of the (needed) recalculations again.  At this point, you&#8217;d then want to rewrite your code so when you create a new object, you also call this new function (so you don&#8217;t have 2 pieces of code that do the same thing, in multiple places.. it&#8217;s easier to maintain, etc.).</p>
<p>However, a better solution (though you may not be able to&#8230; I&#8217;m only looking at an abbreviated version), would be to simply store the 4 or so parameters you pass to the Detonation object (name, lat, lon, yield). You then write functions that automatically create these values for you <i>only when you ask for them</i>.  That way, you can set a new yield, and not waste any time recalculating then&#8230; you could wait to recalculate the values only when you need to.  </p>
<p>The ideal solution is probably somewhere inbetween&#8230;. where you store the 4 parameters, as well creating a function to re-calculate the radius measurements each time&#8230; since you use those so often, it&#8217;d be more efficient (as you said in #1) to calculate them just once.</p>
<p>I know you said you&#8217;d like to look at code, and this is just a high-level overview, but let us know what kinda changes you can make, and we can try to get to code.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->