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


Groups > comp.lang.javascript > #23702 > unrolled thread

Why is it so convoluted to import a .js file in javascript?

Started byjonas.thornvall@gmail.com
First post2014-03-26 16:22 -0700
Last post2014-03-27 22:29 +0100
Articles 20 on this page of 28 — 9 participants

Back to article view | Back to comp.lang.javascript


Contents

  Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-26 16:22 -0700
    Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-27 01:37 -0700
      Re: Why is it so convoluted to import a .js file in javascript? Tim Streater <timstreater@greenbee.net> - 2014-03-27 11:45 +0000
        Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-27 09:36 -0700
          Re: Why is it so convoluted to import a .js file in javascript? Tim Streater <timstreater@greenbee.net> - 2014-03-27 17:17 +0000
          Re: Why is it so convoluted to import a .js file in javascript? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-27 19:48 +0100
            Re: Why is it so convoluted to import a .js file in javascript? "se" <se@no-one.here> - 2014-03-27 20:52 +0100
            Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 08:39 -0700
            Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 08:59 -0700
              Re: Why is it so convoluted to import a .js file in javascript? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-28 18:19 +0100
                Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 10:41 -0700
                  eval() vs. own expression parser (was: Why is it so convoluted to import a .js file in javascript?) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-28 19:11 +0100
                  Re: Why is it so convoluted to import a .js file in javascript? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-28 21:43 +0100
                  Re: Why is it so convoluted to import a .js file in javascript? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-29 18:57 +0100
        Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 08:51 -0700
      Re: Why is it so convoluted to import a .js file in javascript? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-03-27 17:30 +0100
    Re: Why is it so convoluted to import a .js file in javascript? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-27 09:39 +0100
    Re: Why is it so convoluted to import a .js file in javascript? "se" <se@no-one.here> - 2014-03-27 21:12 +0100
      Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 07:11 -0700
        Re: Why is it so convoluted to import a .js file in javascript? John Harris <niam@jghnorth.org.uk.invalid> - 2014-03-28 14:30 +0000
        Re: Why is it so convoluted to import a .js file in javascript? danca <cyberdanny@tiscalinet.it> - 2014-03-28 15:36 +0100
          Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 08:17 -0700
            Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 08:23 -0700
              Re: Why is it so convoluted to import a .js file in javascript? danca <cyberdanny@tiscalinet.it> - 2014-03-29 16:42 +0100
      Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 09:02 -0700
        Re: Why is it so convoluted to import a .js file in javascript? "se" <se@no-one.here> - 2014-03-28 19:00 +0100
          Re: Why is it so convoluted to import a .js file in javascript? jonas.thornvall@gmail.com - 2014-03-28 11:34 -0700
    Re: Why is it so convoluted to import a .js file in javascript? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-27 22:29 +0100

Page 1 of 2  [1] 2  Next page →


#23702 — Why is it so convoluted to import a .js file in javascript?

Fromjonas.thornvall@gmail.com
Date2014-03-26 16:22 -0700
SubjectWhy is it so convoluted to import a .js file in javascript?
Message-ID<d1050ce2-5b06-4bb8-9d69-18cc325b30c0@googlegroups.com>
I decided to try math.js

This is all information on math.js page on howto use it...


// load math.js and create an instance
var mathjs = require('math,js'),
    math = mathjs()

So i pretty much guessed that i should copy the text to my script
But i get following error in firefox

02 ReferenceError: require is not defined div.html:155
00:12:49,743 reflow: 7.15ms
00:12:49,642 TypeError: primearray is undefined //This error is not there normally


So can anyone explain howto invoke math.js in my script.


Why can't a simple
import('../test/test.js'); or append('../test/test.js');
do?

I mean if it is variable conflicts that prevent this can they not get renamed on the fly? 

[toc] | [next] | [standalone]


#23704

Fromjonas.thornvall@gmail.com
Date2014-03-27 01:37 -0700
Message-ID<ce8b01e4-3142-4b81-b103-aab2a92c0b39@googlegroups.com>
In reply to#23702
Den torsdagen den 27:e mars 2014 kl. 00:41:37 UTC+1 skrev Stefan Ram:
> jonas.thornvall@gmail.com writes:
> 
> >// load math.js and create an instance
> 
> >var mathjs = require('math,js'),
> 
> 
> 
>   s/,/./
> 
> 
> 
>   The method »require« is a method of the modules API of
> 
>   Node.js, it is not a part of standard JavaScript AFAIK.
> 
> 
> 
> >Why can't a simple
> 
> >import('../test/test.js'); or append('../test/test.js');
> 
> >do?
> 
> 
> 
>   When JavaScript is running in a web browser, scripts can be
> 
>   loaded in HTML using
> 
> 
> 
> <script type="text/javascript" src="../test/test.js"></script>
> 
> 
> 
>   . JavaScript does not have a means to import a file itself.
> 
>   Maybe because it does not want to include features specific
> 
>   to only some environments, such as filesystem access.

Hello Stefan thanks for you answer, so to be able to call the function, i must place <script type="text/javascript" src="../test/test.js"></script> in another frame?

Or can i have multiple scripts interacting in same page? I want to call math.js function from my own script.

[toc] | [prev] | [next] | [standalone]


#23706

FromTim Streater <timstreater@greenbee.net>
Date2014-03-27 11:45 +0000
Message-ID<270320141145170829%timstreater@greenbee.net>
In reply to#23704
In article <ce8b01e4-3142-4b81-b103-aab2a92c0b39@googlegroups.com>,
<jonas.thornvall@gmail.com> wrote:

> Den torsdagen den 27:e mars 2014 kl. 00:41:37 UTC+1 skrev Stefan Ram:
> > jonas.thornvall@gmail.com writes:

> > 

> Hello Stefan thanks for you answer, so to be able to call the function, i
> must place <script type="text/javascript" src="../test/test.js"></script> in
> another frame?
> 
> Or can i have multiple scripts interacting in same page? I want to call
> math.js function from my own script.

You do like to complicate simple things, don't you?

Decide where is your math.js is going to live, and in the page you want
to use it, put this:

  <script type="text/javascript" src="/path/to/math.js"></script>

where you replace /path/to with the actual path to your math.js script.

Frames have nothing to do with it.

-- 
"Once you adopt the unix paradigm, the variants cease to be a problem - you
bitch, of course, but that's because bitching is fun, unlike M$ OS's, where 
bitching is required to keep your head from exploding." - S Stremler in afc

[toc] | [prev] | [next] | [standalone]


#23708

Fromjonas.thornvall@gmail.com
Date2014-03-27 09:36 -0700
Message-ID<d9854441-f57a-4b17-bf72-a934836819f2@googlegroups.com>
In reply to#23706
Den torsdagen den 27:e mars 2014 kl. 12:45:17 UTC+1 skrev Tim Streater:
> In article <ce8b01e4-3142-4b81-b103-aab2a92c0b39@googlegroups.com>,
> 
> <jonas.thornvall@gmail.com> wrote:
> 
> 
> 
> > Den torsdagen den 27:e mars 2014 kl. 00:41:37 UTC+1 skrev Stefan Ram:
> 
> > > jonas.thornvall@gmail.com writes:
> 
> 
> 
> > > 
> 
> 
> 
> > Hello Stefan thanks for you answer, so to be able to call the function, i
> 
> > must place <script type="text/javascript" src="../test/test.js"></script> in
> 
> > another frame?
> 
> > 
> 
> > Or can i have multiple scripts interacting in same page? I want to call
> 
> > math.js function from my own script.
> 
> 
> 
> You do like to complicate simple things, don't you?
> 
> 
> 
> Decide where is your math.js is going to live, and in the page you want
> 
> to use it, put this:
> 
> 
> 
>   <script type="text/javascript" src="/path/to/math.js"></script>
> 
> 
> 
> where you replace /path/to with the actual path to your math.js script.
> 
> 
> 
> Frames have nothing to do with it.
> 
> 
> 
> -- 
> 
> "Once you adopt the unix paradigm, the variants cease to be a problem - you
> 
> bitch, of course, but that's because bitching is fun, unlike M$ OS's, where 
> 
> bitching is required to keep your head from exploding." - S Stremler in afc

I did place script in same folder as my own HTML document with javascript, i placed above my own script. 
<script type="text/javascript" src="../test/test.js"></script> 
//My script
<script type="text/javascript">

I've tried to use example from math.js site.
And assigned it to a variable.
//THIS IS EXAMPLE ON math.js site
//math.eval('1.2 * (2 + 4.5)'); 

test=math.eval('1.2 * (2 + 4.5)'); 

This is waht konsol in firefox report.
17:28:33,917 reflow: 0.36ms
17:28:33,917 reflow: 0.56ms
17:28:33,851 ReferenceError: math is not defined




[toc] | [prev] | [next] | [standalone]


#23709

FromTim Streater <timstreater@greenbee.net>
Date2014-03-27 17:17 +0000
Message-ID<270320141717216274%timstreater@greenbee.net>
In reply to#23708
In article <d9854441-f57a-4b17-bf72-a934836819f2@googlegroups.com>,
<jonas.thornvall@gmail.com> wrote:

> I did place script in same folder as my own HTML document with javascript, i
> placed above my own script. 
> <script type="text/javascript" src="../test/test.js"></script> 

If it's in the same folder then you should put:

  <script type="text/javascript" src="math.js"></script>

-- 
"Once you adopt the unix paradigm, the variants cease to be a problem - you
bitch, of course, but that's because bitching is fun, unlike M$ OS's, where 
bitching is required to keep your head from exploding." - S Stremler in afc

[toc] | [prev] | [next] | [standalone]


#23710

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-03-27 19:48 +0100
Message-ID<XnsA2FDC97BC475Beejj99@194.109.133.133>
In reply to#23708
jonas.thornvall@gmail.com wrote on 27 mrt 2014 in comp.lang.javascript:

> test=math.eval('1.2 * (2 + 4.5)'); 
> 17:28:33,851 ReferenceError: math is not defined

So do you understand why it is not defined?

Perhaps this NG is not a place to discuss 
the confines of a convoluted [your words] library.

Methinks you don't even need it,
try to use pain Javascript. 

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#23711

From"se" <se@no-one.here>
Date2014-03-27 20:52 +0100
Message-ID<lh1vh0$49i$1@dont-email.me>
In reply to#23710
"Evertjan." <exxjxw.hannivoort@inter.nl.net> skrev i meddelelsen 
news:XnsA2FDC97BC475Beejj99@194.109.133.133...
> jonas.thornvall@gmail.com wrote on 27 mrt 2014 in comp.lang.javascript:
>
>> test=math.eval('1.2 * (2 + 4.5)');
>> 17:28:33,851 ReferenceError: math is not defined

> Methinks you don't even need it,
> try to use pain Javascript.

> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)


>But why this ad hominem remark where you could explain and teach us?
>Oh, ofcourse, there is @no-one.there to do that.

> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress) 

[toc] | [prev] | [next] | [standalone]


#23720

Fromjonas.thornvall@gmail.com
Date2014-03-28 08:39 -0700
Message-ID<6422f57f-be91-4633-9611-5a754d0fdc88@googlegroups.com>
In reply to#23710
Den torsdagen den 27:e mars 2014 kl. 19:48:23 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 27 mrt 2014 in comp.lang.javascript:
> 
> 
> 
> > test=math.eval('1.2 * (2 + 4.5)'); 
> 
> > 17:28:33,851 ReferenceError: math is not defined
> 
> 
> 
> So do you understand why it is not defined?
> 
> 
> 
> Perhaps this NG is not a place to discuss 
> 
> the confines of a convoluted [your words] library.
> 
> 
> 
> Methinks you don't even need it,
> 
> try to use pain Javascript. 
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

Actually i do need an evaluator that can parse/handle operators +-*/^ doing integer arithmetic in correct order, i have written one before and it seem necessary todo again, because pure silliness from the JavaScript Community. 

I mean 17 years really and this is the state of art evaluator? I do not expect it todo trigonometry, degrees and radians, but simple expressions? It is not a giant task, and everyone doing scripts dealing with accounting and spreadsheets would benefit.

A working parser for evaluation of expressions using +-*/^ and roots should been there to begin with?

[toc] | [prev] | [next] | [standalone]


#23723

Fromjonas.thornvall@gmail.com
Date2014-03-28 08:59 -0700
Message-ID<e96817ba-43dd-412e-ac44-617254e21546@googlegroups.com>
In reply to#23710
Den torsdagen den 27:e mars 2014 kl. 19:48:23 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 27 mrt 2014 in comp.lang.javascript:
> 
> 
> 
> > test=math.eval('1.2 * (2 + 4.5)'); 
> 
> > 17:28:33,851 ReferenceError: math is not defined
> 
> 
> 
> So do you understand why it is not defined?
> 
> 
> 
> Perhaps this NG is not a place to discuss 
> 
> the confines of a convoluted [your words] library.
> 
> 
> 
> Methinks you don't even need it,
> 
> try to use pain Javascript. 
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

I was wrong apparently it do +- */ in correct order, but it has problems with Powers, no problems i can parse them.

[toc] | [prev] | [next] | [standalone]


#23727

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-03-28 18:19 +0100
Message-ID<XnsA2FEBA5B9A273eejj99@194.109.133.133>
In reply to#23723
jonas.thornvall@gmail.com wrote on 28 mrt 2014 in comp.lang.javascript:
> I wrote:
>> Methinks you don't even need it,
>> try to use pain Javascript. 
>> -- 
>> Evertjan.
>> The Netherlands.

[Please do not quote signatures on usenet]
 
> I was wrong apparently it do +- */ in correct order, but it has problems
> with Powers, no problems i can parse them. 

Could it be that you are too quick in your judgements?

Methinks "you" have these problems, "it" does not, why should "it"?
 
> problems with Powers

That's part of growing up. 

Is that the reason for the capitalisation,
or are you referring to Colin Powers?

btw, building your own arithmetic parser is fun and educational,
even if you don't realy need it, as Javascript does a good job here.

We of the assembler era all did this once on a time long, long ago.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#23729

Fromjonas.thornvall@gmail.com
Date2014-03-28 10:41 -0700
Message-ID<00d68cb0-4463-426a-859d-125781cd2f56@googlegroups.com>
In reply to#23727
Den fredagen den 28:e mars 2014 kl. 18:19:10 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 28 mrt 2014 in comp.lang.javascript:
> 
> > I wrote:
> 
> >> Methinks you don't even need it,
> 
> >> try to use pain Javascript. 
> 
> >> -- 
> 
> >> Evertjan.
> 
> >> The Netherlands.
> 
> 
> 
> [Please do not quote signatures on usenet]
> 
>  
> 
> > I was wrong apparently it do +- */ in correct order, but it has problems
> 
> > with Powers, no problems i can parse them. 
> 
> 
> 
> Could it be that you are too quick in your judgements?
> 
> 
> 
> Methinks "you" have these problems, "it" does not, why should "it"?
> 
>  
> 
> > problems with Powers
> 
> 
> 
> That's part of growing up. 
> 
> 
> 
> Is that the reason for the capitalisation,
> 
> or are you referring to Colin Powers?
> 
> 
> 
> btw, building your own arithmetic parser is fun and educational,
> 
> even if you don't realy need it, as Javascript does a good job here.
> 
> 
> 
> We of the assembler era all did this once on a time long, long ago.
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

Well feel free to test if you are correct in you assesment. 
Javascript can not handle 3^2 and it can not handle 3--4. "and maybe that is not necessary". 

I do know that it can handle Math.pow() but one can not require the users to know that so i guess i have to scan string and parse 3^2--4 into Math.pow(3,2)-4 before pass it to eval()

[toc] | [prev] | [next] | [standalone]


#23734 — eval() vs. own expression parser (was: Why is it so convoluted to import a .js file in javascript?)

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-03-28 19:11 +0100
Subjecteval() vs. own expression parser (was: Why is it so convoluted to import a .js file in javascript?)
Message-ID<5335bb43$0$22623$9b4e6d93@newsspool1.arcor-online.net>
In reply to#23729
jonas.thornvall@gmail.com wrote:

> I do know that it can handle Math.pow() but one can not require the
> users to know that so i guess i have to scan string and parse 3^2--4
> into Math.pow(3,2)-4 before pass it to eval()

If you want to eval() user input, you most likely have to parse the
string for security reasons, anyway.  Writing a small expression parser
shouldn't be too hard (and I presume there are libraries to be found on
the web which help in one way or another), and then you can even do
without eval().

BTW: it is doubtful whether 3^2--4 should be translated to
Math.pow(3,2)-4.  If a double minus sign is accepted at all, it might be
better to treat it as 3^2-(-4), i.e. 3^2+4.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#23737

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-03-28 21:43 +0100
Message-ID<1657043.3hh7LR6cIB@PointedEars.de>
In reply to#23729
Stefan Ram wrote:

> jonas.thornvall@gmail.com writes:
>> Javascript can not handle 3^2
> 
>   I just wrote the following evaluator that can evaluate
>   expressions like »6+3*2^3+1«. All its errors and features
>   gaps are meant to be an exercise for the reader.

This would have been more educational had you used a code style that was at 
least easily readable, if not common.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#23741

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-03-29 18:57 +0100
Message-ID<1658884.GDCoxO0Dda@PointedEars.de>
In reply to#23729
Stefan Ram wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>I just wrote the following evaluator that can evaluate
>>expressions like »6+3*2^3+1«. All its errors and features
>>gaps are meant to be an exercise for the reader.
> 
>   The new version
> 
>       - now correctly treats 2^3^2 right-associatively,
>       - has additional operators "/" and binary "-", and
>       - can deal with multi-digit numerals.
> 
> <!DOCTYPE HTML><html><head><title>Main</title>
> <meta charset="UTF-8"></head><body><pre><code><script>

Your code style, although apparently consistent, still is only barely 
readable.  Your code is very inefficient and error-prone.

The part of the code that does not depend on output belongs in the “head” 
element.
 
> function Scanner( source ){ this.source = source; this.pos = 0; };
> Scanner.prototype =
> { check: function( pattern )
>   { var next = this.source.substring( this.pos, this.pos + 1 );

  var next = this.source.charAt(this.pos);

or in some implementations (especially those of ES5+)

  var next = this.source[this.pos];

<http://PointedEars.de/es-matrix/?filter=string\[>

>     if( pattern.exec( next )){ ++this.pos; return next }
>     else return false; },

It does not make any sense to use regular expressions and at the same time 
to not use the resulting matches.

>   numeral: function()
>   { var next = /[0-9]+/.exec( this.source.substring( this.pos ));
>     this.pos += next[ 0 ].length; return next[ 0 ]; }, };
> 
> var ex = Object.create( null );
> ex[ "^" ]= Math.pow;
> ex[ "*" ]= function( a, b ){ return a * b };
> ex[ "/" ]= function( a, b ){ return a / b };
> ex[ "+" ]= function( a, b ){ return a*1 + b*1 };
> ex[ "-" ]= function( a, b ){ return a - b };

This can be compacted and optimized into

  var ex = Object.create(null, {
    "^": {value: Math.pow},
    "*": {value: function (a, b) { return a * b; }},
    "/": {value: function (a, b) { return a / b; }},
    "+": {value: function (a, b) { return (+a) + (+b); }},
    "-": {value: function (a, b) { return a - b; }}
  });

An important difference to the above is that these properties are read-only 
and not enumerable.  Otherwise the code begs the question why a simple, more 
compatible, Object initialiser would not suffice:

  var ex = {
    // …
  };
 
> var left_associative = Object.create( null );
> left_associative[ "^" ]= false;
> left_associative[ "*" ]= true;
> left_associative[ "/" ]= true;
> left_associative[ "+" ]= true;
> left_associative[ "-" ]= true;

Same here.  In fact, it might be more efficient, and certainly makes more 
sense data-wise, to have the associativity of an operator as the property of 
an operator, not some unrelated object:

  var operators = {
    "…": {
      call: function () { … },
      leftAssociative: …
    },

    /∕ …
  };
 
> function Parser( source ){ this.scanner = new Scanner( source ); };
> Parser.prototype =

As you have been told before, this overwrites the prototype property, 
setting the value of the  “constructor” property of Instance to a reference 
to the value of the “constructor” property of the RHS value.

> { numeral:  function( me ){ return me.scanner.numeral(); },
>   parse: function( me, op, next )
>   { var result = next( me ); var sym;
>     while( sym = me.scanner.check( op ))
>     result = ex[ sym ]( result,
>       ( left_associative[ sym ]? next( me ): me.parse( me, op, next )));
>     return result; },

Completely unmaintainable.  Kids, don't try this at home.

>   power:   function( me ){ return me.parse( me, /[\^]/,  me.numeral ); },
>   product: function( me ){ return me.parse( me, /[*\/]/, me.power   ); },
>   sum:     function( me ){ return me.parse( me, /[+-]/,  me.product ); },
>   start:   function(){     return this.sum( this ); }};

It is pointless and less efficient to pass the “this” value to a function 
called as a method of the “this” value.

  ({
    foo: function (me) {
      return me;
    },

    bar: function () {
      this.foo(this);
    }
  }).bar();

is semantically equivalent to

  ({
    foo: function () {
      return this;
    },

    bar: function () {
      this.foo();
    }
  }).bar();

[“this” has nothing to do with scope.  That it had is a common beginner’s 
misconception.]
 
> function evl( x ){ var parser = new Parser( x ); return parser.start(); }
> 
> function check( x, y )
> { var e = evl( x ); var r = e == y*1;

Because we are dealing with floating-point values, converting to Number 
explicitly with unary “+” is probably more efficient than converting 
implicitly by multiplying by 1.  It is also less likely to be upwards-
incompatible (should there in be an implementation in the future
that overloads “*” as string repetition operator in the future [1]).


[1] cf. <http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.repeat>
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#23722

Fromjonas.thornvall@gmail.com
Date2014-03-28 08:51 -0700
Message-ID<4f6d1f61-e8ae-47f8-af04-8f431cb649e1@googlegroups.com>
In reply to#23706
Den torsdagen den 27:e mars 2014 kl. 12:45:17 UTC+1 skrev Tim Streater:
> In article <ce8b01e4-3142-4b81-b103-aab2a92c0b39@googlegroups.com>,
> 
> <jonas.thornvall@gmail.com> wrote:
> 
> 
> 
> > Den torsdagen den 27:e mars 2014 kl. 00:41:37 UTC+1 skrev Stefan Ram:
> 
> > > jonas.thornvall@gmail.com writes:
> 
> 
> 
> > > 
> 
> 
> 
> > Hello Stefan thanks for you answer, so to be able to call the function, i
> 
> > must place <script type="text/javascript" src="../test/test.js"></script> in
> 
> > another frame?
> 
> > 
> 
> > Or can i have multiple scripts interacting in same page? I want to call
> 
> > math.js function from my own script.
> 
> 
> 
> You do like to complicate simple things, don't you?
> 
> 
> 
> Decide where is your math.js is going to live, and in the page you want
> 
> to use it, put this:
> 
> 
> 
>   <script type="text/javascript" src="/path/to/math.js"></script>
> 
> 
> 
> where you replace /path/to with the actual path to your math.js script.
> 
> 
> 
> Frames have nothing to do with it.
> 
> 
> 
> -- 
> 
> "Once you adopt the unix paradigm, the variants cease to be a problem - you
> 
> bitch, of course, but that's because bitching is fun, unlike M$ OS's, where 
> 
> bitching is required to keep your head from exploding." - S Stremler in afc

Well loading the other script in a hidden frame, would probably make the functions defined by default...

[toc] | [prev] | [next] | [standalone]


#23707

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2014-03-27 17:30 +0100
Message-ID<5gk8j9thbfbql72c6t4dkkd6hhn0g1rk0m@4ax.com>
In reply to#23704
On Thu, 27 Mar 2014 01:37:30 -0700 (PDT),
jonas.thornvall@gmail.com wrote:

>Hello Stefan thanks for you answer, so to be able to call the function, i must place <script type="text/javascript" src="../test/test.js"></script> in another frame?
>
>Or can i have multiple scripts interacting in same page? I want to call math.js function from my own script.

You can load as many .js files as you like into one HTML page.
The effect is the same as if you put their contents into one
file and load that.

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#23705

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-03-27 09:39 +0100
Message-ID<XnsA2FD62551E3FBeejj99@194.109.133.133>
In reply to#23702
ram@zedat.fu-berlin.de (Stefan Ram) wrote on 27 mrt 2014 in 
comp.lang.javascript:

> When JavaScript is running in a web browser, scripts can be
> loaded in HTML using
> 
> <script type="text/javascript" src="../test/test.js"></script>

Indeed.

>   JavaScript does not have a means to import a file itself.

???

<script type='text/javascript'>

document.write('<s' +
'cript type="text/javascript" ' +
'src="http://....com/test/myJs.js"></s' +
'cript>');

</script>
</head>
<body>

[not tested]

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#23712

From"se" <se@no-one.here>
Date2014-03-27 21:12 +0100
Message-ID<lh20mo$eoc$1@dont-email.me>
In reply to#23702
<jonas.thornvall@gmail.com> skrev i meddelelsen 
news:d1050ce2-5b06-4bb8-9d69-18cc325b30c0@googlegroups.com...
>I decided to try math.js
>
> This is all information on math.js page on howto use it...
>
>
> // load math.js and create an instance
> var mathjs = require('math,js'),
>    math = mathjs()
>
> So i pretty much guessed that i should copy the text to my script
> But i get following error in firefox
>
> 02 ReferenceError: require is not defined div.html:155
> 00:12:49,743 reflow: 7.15ms
> 00:12:49,642 TypeError: primearray is undefined //This error is not there 
> normally
>
>
> So can anyone explain howto invoke math.js in my script.
>
>
> Why can't a simple
> import('../test/test.js'); or append('../test/test.js');
> do?
>
> I mean if it is variable conflicts that prevent this can they not get 
> renamed on the fly?

Go here to learn basics of javascript. But first of; learn basics
of html coding same place.
http://www.w3schools.com/js/default.asp

Make a new page and paste below. Perhaps it'll give you
an idea to start off. Put in your own expression:

<head>
<script type="text/javascript">
  var expres='(5*3.5-2.5)/3';
   function mathEval(expres) {
       document.write(eval(expres));
   }
</script>
</head>

<body>
     <button type="button" name="mBut" 
onclick="mathEval(expres);">Click</button>
</body>

[toc] | [prev] | [next] | [standalone]


#23715

Fromjonas.thornvall@gmail.com
Date2014-03-28 07:11 -0700
Message-ID<286e9794-3791-4624-9565-682748a5785b@googlegroups.com>
In reply to#23712
Den torsdagen den 27:e mars 2014 kl. 21:12:29 UTC+1 skrev se:
> <jonas.thornvall@gmail.com> skrev i meddelelsen 
> 
> news:d1050ce2-5b06-4bb8-9d69-18cc325b30c0@googlegroups.com...
> 
> >I decided to try math.js
> 
> >
> 
> > This is all information on math.js page on howto use it...
> 
> >
> 
> >
> 
> > // load math.js and create an instance
> 
> > var mathjs = require('math,js'),
> 
> >    math = mathjs()
> 
> >
> 
> > So i pretty much guessed that i should copy the text to my script
> 
> > But i get following error in firefox
> 
> >
> 
> > 02 ReferenceError: require is not defined div.html:155
> 
> > 00:12:49,743 reflow: 7.15ms
> 
> > 00:12:49,642 TypeError: primearray is undefined //This error is not there 
> 
> > normally
> 
> >
> 
> >
> 
> > So can anyone explain howto invoke math.js in my script.
> 
> >
> 
> >
> 
> > Why can't a simple
> 
> > import('../test/test.js'); or append('../test/test.js');
> 
> > do?
> 
> >
> 
> > I mean if it is variable conflicts that prevent this can they not get 
> 
> > renamed on the fly?
> 
> 
> 
> Go here to learn basics of javascript. But first of; learn basics
> 
> of html coding same place.
> 
> http://www.w3schools.com/js/default.asp
> 
> 
> 
> Make a new page and paste below. Perhaps it'll give you
> 
> an idea to start off. Put in your own expression:
> 
> 
> 
> <head>
> 
> <script type="text/javascript">
> 
>   var expres='(5*3.5-2.5)/3';
> 
>    function mathEval(expres) {
> 
>        document.write(eval(expres));
> 
>    }
> 
> </script>
> 
> </head>
> 
> 
> 
> <body>
> 
>      <button type="button" name="mBut" 
> 
> onclick="mathEval(expres);">Click</button>
> 
> </body>

I can only say one thing if they are that fucking stupid they make examples that do not use the actual function names, but made up ones. They should fucking take brainsurgery for idiocy.

I will try it and mail the fucking idiot if that turn out to be the case.

[toc] | [prev] | [next] | [standalone]


#23716

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2014-03-28 14:30 +0000
Message-ID<vr1bj9pgnnerkt0bt3l6njd6r05ms95u2b@4ax.com>
In reply to#23715
On Fri, 28 Mar 2014 07:11:23 -0700 (PDT), jonas.thornvall@gmail.com
wrote:

>Den torsdagen den 27:e mars 2014 kl. 21:12:29 UTC+1 skrev se:
>> <jonas.thornvall@gmail.com> skrev i meddelelsen 
>> 
>> news:d1050ce2-5b06-4bb8-9d69-18cc325b30c0@googlegroups.com...
>> 
>> >I decided to try math.js
  <snip>


>I can only say one thing if they are that fucking stupid they make examples that do not use the actual function names, but made up ones. They should fucking take brainsurgery for idiocy.
>
>I will try it and mail the fucking idiot if that turn out to be the case.

Who are "they" and why are you so annoyed with them ?

  John

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web