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 8 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 2 of 2 — ← Prev page 1 [2]


#23717

Fromdanca <cyberdanny@tiscalinet.it>
Date2014-03-28 15:36 +0100
Message-ID<lh41dl$pe6$1@dont-email.me>
In reply to#23715
Il 28/03/2014 15:11, jonas.thornvall@gmail.com ha scritto:

>
> 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.
>
"Javascript" is a frustrating experience.
Everybody here I think has had some moments of amok. Try to think "Om 
Mani Padme Javascript" and go on.
:-)
Dan

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


#23718

Fromjonas.thornvall@gmail.com
Date2014-03-28 08:17 -0700
Message-ID<a3540009-14a6-4f3d-97ff-e1ce8dcccf3f@googlegroups.com>
In reply to#23717
Den fredagen den 28:e mars 2014 kl. 15:36:35 UTC+1 skrev danca:
> Il 28/03/2014 15:11, jonas.thornvall@gmail.com ha scritto:
> 
> 
> 
> >
> 
> > 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.
> 
> >
> 
> "Javascript" is a frustrating experience.
> 
> Everybody here I think has had some moments of amok. Try to think "Om 
> 
> Mani Padme Javascript" and go on.
> 
> :-)
> 
> Dan

I read a bit to fast i did not see he used the built in eval function in his example, not the one in math.js.

But it still kind of suck, i guess this is how languages like python come to be, people get tired and build their own kernel to do arithmetic. Because they simply can not stand Reading a fucking 300 page manual to import a script with functions. And why is the JavaScript eval so flawed not grasping operator order, if i put my mind to it i can write a fully consistent arithmetic parser in a week. And JavaScript is like 17 years old? So i do not know...

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


#23719

Fromjonas.thornvall@gmail.com
Date2014-03-28 08:23 -0700
Message-ID<a349bc8b-ae0b-493c-a8da-ce589a8d9393@googlegroups.com>
In reply to#23718
Den fredagen den 28:e mars 2014 kl. 16:17:31 UTC+1 skrev jonas.t...@gmail.com:
> Den fredagen den 28:e mars 2014 kl. 15:36:35 UTC+1 skrev danca:
> 
> > Il 28/03/2014 15:11, jonas.thornvall@gmail.com ha scritto:
> 
> > 
> 
> > 
> 
> > 
> 
> > >
> 
> > 
> 
> > > 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.
> 
> > 
> 
> > >
> 
> > 
> 
> > "Javascript" is a frustrating experience.
> 
> > 
> 
> > Everybody here I think has had some moments of amok. Try to think "Om 
> 
> > 
> 
> > Mani Padme Javascript" and go on.
> 
> > 
> 
> > :-)
> 
> > 
> 
> > Dan
> 
> 
> 
> I read a bit to fast i did not see he used the built in eval function in his example, not the one in math.js.
> 
> 
> 
> But it still kind of suck, i guess this is how languages like python come to be, people get tired and build their own kernel to do arithmetic. Because they simply can not stand Reading a fucking 300 page manual to import a script with functions. And why is the JavaScript eval so flawed not grasping operator order, if i put my mind to it i can write a fully consistent arithmetic parser in a week. And JavaScript is like 17 years old? So i do not know...

It is so bad and enveloped in mudpie one could think Pointeears had his finger with development.

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


#23738

Fromdanca <cyberdanny@tiscalinet.it>
Date2014-03-29 16:42 +0100
Message-ID<lh6pll$v32$1@dont-email.me>
In reply to#23719
Il 28/03/2014 16:23, jonas.thornvall@gmail.com ha scritto:

> It is so bad and enveloped in mudpie one could think Pointeears had his finger with development.
>
Good guess.
ECMASCRIPT=Every Common Man Avoid Such Cryptical Rotten Involuted 
Pain-in-the-ass Thing
:-) Just to joke of course.
Dan

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


#23724

Fromjonas.thornvall@gmail.com
Date2014-03-28 09:02 -0700
Message-ID<5d08d1c6-2291-4c72-957c-07d75b6062b0@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 was wrong apparently it do +- */ in correct order, but it has problems with Powers, no problems i can parse them. I will only do integer arithmetics for now so no roots.

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


#23732

From"se" <se@no-one.here>
Date2014-03-28 19:00 +0100
Message-ID<lh4dbg$qv7$1@dont-email.me>
In reply to#23724
<jonas.thornvall@gmail.com> skrev i meddelelsen 
news:5d08d1c6-2291-4c72-957c-07d75b6062b0@googlegroups.com...
> 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 was wrong apparently it do +- */ in correct order, but it has problems 
> with Powers, no problems i can parse them. I will only do integer 
> arithmetics for now so no roots.

Learn to use javascript Math object still same place:
http://www.w3schools.com/jsref/jsref_obj_math.asp
http://www.w3schools.com/jsref/jsref_obj_math.asp
Or put your energy into writing your own mathparser instead of curse and 
swear.
Try this:
var res=eval(expres);
document.write(Math.sqrt(res));
// document.write(Math.pow(res,2));

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


#23735

Fromjonas.thornvall@gmail.com
Date2014-03-28 11:34 -0700
Message-ID<2ddd29e6-5ec2-4d5d-ad6e-4503373714b1@googlegroups.com>
In reply to#23732
Den fredagen den 28:e mars 2014 kl. 19:00:37 UTC+1 skrev se:
> <jonas.thornvall@gmail.com> skrev i meddelelsen 
> 
> news:5d08d1c6-2291-4c72-957c-07d75b6062b0@googlegroups.com...
> 
> > 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 was wrong apparently it do +- */ in correct order, but it has problems 
> 
> > with Powers, no problems i can parse them. I will only do integer 
> 
> > arithmetics for now so no roots.
> 
> 
> 
> Learn to use javascript Math object still same place:
> 
> http://www.w3schools.com/jsref/jsref_obj_math.asp
> 
> http://www.w3schools.com/jsref/jsref_obj_math.asp
> 
> Or put your energy into writing your own mathparser instead of curse and 
> 
> swear.
> 
> Try this:
> 
> var res=eval(expres);
> 
> document.write(Math.sqrt(res));
> 
> // document.write(Math.pow(res,2));

I have a user defined integer input function that i render. It could basicly be a function like x^y+-z. I only deal integer part so no reals yet, painting out the integer part, just the way i paint out geometric sequense see.

The idea is that the user should be able to input things the Mersenne sequense
2x-1 in the form yx+-z and x^y+-z? and get it plotted out just the way i plot out  as dynamical sequenses. 
http://web.comhem.se/jonasth/prime0.992/div.html

So there could be restrictions to just put in x,y,z or a limitd number of variables in input fields. But what i reall would like is the ability for the user to input their own functions that deal with integers. Actually they can input whatever they want but for now it will only show integer result.


Example
http://youtu.be/09JslnY7W_k
So the x above 

http://web.comhem.se/jonasth/prime0.992/div.html

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


#23713

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-03-27 22:29 +0100
Message-ID<5419492.dk8GnlDV4K@PointedEars.de>
In reply to#23702
Stefan Ram wrote:

> 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,

ACK.

>   it is not a part of standard JavaScript AFAIK.

There is no “standard JavaScript”; the various implementations/languages 
that call themselves „JavaScript“ (most notably: JavaScript™, JScript, V8, 
Opera ECMAScript, and KJS) are *implementations of* a(n Ecma) standard, the 
ECMAScript Language Specification (ECMA-262).  Conforming implementations of 
ECMAScript *may extend* the Specification’s algorithms and syntax:

<http://PointedEars.de/es-matrix>

This function is not specified in ECMAScript (yet?), and AFAIK it is not 
available in any „JavaScript“.  In Node.js, it is a feature provided by the 
host environment that runs V8 JavaScript:

<http://nodejs.org/api/modules.html>
 
>>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>

“script” elements can also be inserted dynamically, causing the script code 
to be loaded, which is closest to Node.js's approach.  I do not think this 
is limited to HTML.

However, for this to work reliably, the host environment must support either 
a way to determine when the script resource has been loaded (and parsed) – 
this is available in a so far conforming implementation of W3C DOM Level 3 
Events (WD) [1] – or synchronous XHR (which allows the normal program flow 
to continue only after the resource has been loaded; the usual caveats 
apply).

An example for the former is:

  function require (source, callback)
  {
    var script = document.createElement("script");
    script.addEventListener("load", callback);
    script.src = source;

    /* HTML5/WHATWG HTML only */
    document.head.appendChild(script);
  }

  require("http://script.example/foo.js", function () {
    console.log("Script loaded");
  });

(There are libraries that implement and improve this or a similar approach; 
so far none can be recommended, none can be recommended against.  Use it and 
them with caution.)

A proof of concept for the latter is provided by jsx.importFrom() and 
jsx.importOnce() in JSX:object.js [2]
 
>   . 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.

ACK.

________
[1] <http://www.w3.org/TR/DOM-Level-3-Events/#event-type-load>
[2] <http://PointedEars.de/wsvn/JSX/trunk/object.js>
    (Note that jsx.require() does _not_ implement the asynchronous approach
    yet.)
-- 
PointedEars

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

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

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


csiph-web