17 Aug 2009

JavaScript __LINE__ and “this” Substitutes

Leaving a longer explanation to aside, the following code demonstrates, how to overcome the absence of the __LINE__ and the proper semantics of the “this” in the JavaScript.

function niceclass(){
    var self_public_=this; // Yes, that's the first "innovation".

    this.a_public_field='whatever';
    function a_private_method(){
        document.write('Public fields value is:'+self_public_.a_public_field);
    }

    this.a_public_method=function(){
        try{
            a_private_method();
        } catch (err){
            // If all of the methods have try-catch-s with
            // Globally Unique Identifiers Copy/Pasted from
            // http://www.guidgenerator.com/ , then
            // it's possible to find out the faulty region even
            // when the JavaScript does not have the __LINE__ support.
            throw "GUID== ba6e3063-9438-42a4-a041-e8fd635fb4c5"+
            "\nerr=="+err+"\n------------------------\n";
        } // catch
    } // this.a_public_method
} // niceclass

window.onload=function(){
    var v1=new niceclass();
    v1.a_public_method();
    v1.a_public_field='Another value';
    v1.a_public_method();
} // window.onload

For the sake of correctness, I have to give credit to the http://www.quirksmode.org/js/this.html and the
http://jspro.org/. Of course those were not the only sources, but as of August 2009 I found them to be the best that I could find.

++++++++++++++++++++++

Update at 2013_04_27:
Tools for debugging and editing GUID-marked JavaScript reside within the BSD-licensed GUID_trace package, which is part of the mmmv_devel_tools package.

The GUID_trace package components assume that GUID-s are surrounded by either double quotes or single quotes, like
 
GUID=="ba6e3063-9438-42a4-a041-e8fd635fb4c5" 
GUID=='ba6e3063-9438-42a4-a041-e8fd635fb4c5'


3 Aug 2009

About the Feasibility of Hydrogen as a Gasoline Replacement

According to my calculations, if one compares gasoline and energetically identical amount of hydrogen, then the price of a gasoline forms about 86% of the price of the hydrogen provided that only green electricity is used for producing the hydrogen and that there are no energy losses within the hydrogen production process.
The price of energetically equivalent amount of jet fuel, kerosene, forms about 90% of the price of the hydrogen.

Conclusion: both, in the case of cars and flying machines, the green electricity based hydrogen seems to be economically feasible, but unfortunately it would still be too expensive to make it affordable to have helicopter based ambulances in regular use. For example, a 300km two-way flight with the Eurocopter AS365 seems to cost at least about 200 Euro-s.

The good news is that if someone figures out a way, how to decompose water by using solar energy and some microbes or chemical reaction, then the hydrogen based aviation might become affordable. :-)

The Mathematica notebook source:

(* All of the following calculations are about one litre of gasoline.*)

Needs["Units`"];
litersPerGallon = 3.78541 Liter/Gallon;
cubicMetersPerGallon = litersPerGallon/(1000*Liter)*Meter^3;

(* http://www32.wolframalpha.com/input/?i=gasoline *)

gasolineEnergy = 47.73 *10^6 Joule/Kilogram;
gasolineDensity = 0.735*10^6*Kilogram/(1000*Meter^3);

gasolineEnergyPerCubicMeter = gasolineDensity*gasolineEnergy;
gasolineEnergyPerLiter = (gasolineEnergyPerCubicMeter*Meter^3)/(
1000*Liter);
eurosPerKroon = 1/15.7 *Euro;(* www.seb.ee *)

greenElectricityUnitPrice = 1.8*eurosPerKroon;
gasolinePriceLiter = 15*eurosPerKroon
gasolineEquivalentElectricitySalesUnits = (
gasolineEnergyPerLiter*(1*Liter))/(3600000 *Joule);
gasolineEquivalentGreenElectricityPrice =
gasolineEquivalentElectricitySalesUnits*greenElectricityUnitPrice
ratioGasoline = \
gasolinePriceLiter/gasolineEquivalentGreenElectricityPrice



dollarsPerKroon = 1/12*Dollar; (* www.seb.ee *)

eurosPerDollar = eurosPerKroon/dollarsPerKroon;

(* http://www32.wolframalpha.com/input/?i=kerosene *)

keroseneDensity = (0.819*10^6*Kilogram)/(1000*Meter^3);

(* http://hypertextbook.com/facts/2003/EvelynGofman.shtml *)

keroseneEnergy = 42.8*10^6 Joule/Kilogram;
keroseneEnergyPerCubicMeter = keroseneDensity*keroseneEnergy;

(* http://www.nyserda.org/energy_information/nyepg.asp
http://www.iata.org/whatwedo/economics/fuel_monitor/index.htm
*)
kerosenePricePerGallon = (5*Dollar)/Gallon*eurosPerDollar;


gasolineEquivalentKeroseneMass =
gasolineEnergyPerLiter/keroseneEnergy*(1*Liter);
gasolineEquivalentKeroseneVolume = gasolineEquivalentKeroseneMass/
keroseneDensity;
gasolineEquivalentKeroseneVolumeGallons =
gasolineEquivalentKeroseneVolume/cubicMetersPerGallon;
gasolineEquivalentKerosenePrice =
gasolineEquivalentKeroseneVolumeGallons*kerosenePricePerGallon
ratioKerosene = \
gasolineEquivalentKerosenePrice/gasolineEquivalentGreenElectricityPrice


(* http://www.eurocopter.com/site/en/ref/Characteristics_99.html *)

eurocopterAS365Power = 700*10^3 Joule/Second;
eurocopterAS365Speed = 269000/3600*Meter/Second;
distanceFromHospital = 300*10^3 Meter;
flightDistance = 2*distanceFromHospital;
flightTakeoffsAndLandingsDuration = 15*60*Second;
flightDuration =
flightDistance/eurocopterAS365Speed +
flightTakeoffsAndLandingsDuration;
flightDurationInHours = flightDuration/(3600*Second)*1.0*Hour

flightEnergy = flightDuration*eurocopterAS365Power
flightEnergyPriceElectricity =
flightEnergy/(3600000*Joule)*greenElectricityUnitPrice