Forums > Javascript

Possible to include JavaScript file into another?

Feb 09 2014 | 8:03 am

I would like to put some JavaScript functions I use often in a separate file to prevent copy/paste. Is it somehow possible to include a JavaScript file into another? Or is there a workaround?

Feb 09 2014 | 11:49 am

Hi !

well . you can include js content by putting your Utils into Cycling ’74/jsextensions/ folder .
This way your functions are seen within every JS project used in max .
Personally i would love to have #include directive as an option and be specific to the current project, but thats not possible without writing a compiler for JS (someone did) ,
every changes require recompiling .

There is third option . Pack your utils into Global object inside one JS instance and access it in another .

mostly im using the last one .

Feb 10 2014 | 12:34 am

Thanks for the tip with the Global. Works fine!

May 17 2015 | 10:57 am

Excuse me, but I’m not sure to understand that third solution about global object :/ someone can explain ?

May 17 2015 | 12:17 pm

U are able to setup a global object in one JS instance, that holds your methods/variables/objects and access them inside other JS instances .
But in Max 7 weve got new directives that let us concatinate functionality .

May 17 2015 | 1:45 pm

It’s very unfortunate that the implementation of JS require is wrong – or at least, it was wrong in the first release of Max 7 (I haven’t upgraded, partly for that reason, partly because I have shows coming up and want to wait until there’s a break with some time to kill before potentially destabilizing my world. I hear good things about Max 7 but experience with software in general leads me to caution…)

The issue is that you can’t refer to files in subdirectories – even though the Common JS spec requires it. It’s unfortunate, because most third-party Common JS packages do use subdirectories in their require sections, rendering them incompatible with Max/MSP’s JS implementation.

I do hope this gets fixed and I will upgrade to Max 7 the moment it is… hint hint hint! :-) There was some argument last time this came up as to whether this was even a bug but I think the Common JS specification is authoritative in this matter…

May 17 2015 | 4:13 pm

OK :) thank!

May 18 2015 | 8:21 am

Thanks @TOM SWIRLY ! its good to be aware before jumping in . Indeed i would be surprised because i would expect it to behave as its origin .
by the way : Wanst it you who wrote compiler for JS that let us concatinate files ?

May 18 2015 | 8:39 am

Heh, well, I wrote the examples of this, but it actually uses gcc and make, standard tools that are on pretty well every machine!

I’d love to stop having that phase – if nothing else to avoid the error where I change the program and forget to compile them – and perhaps when Max 7 JS handles relative paths I can!

By the way, my Max style has completely changed now – my patches have almost no wires in them! Instead I have a single Javascript box that everything connects to. Within that JS box is all my logic – plus I directly find the Max boxes and use the message method to send data right them. I also have a way to automatically connect inlet to object method calls so I just have to change a table to change my inputs.

It makes my life much easier when I’m not dragging wires to land on tiny inlets… :-)

May 18 2015 | 8:48 am

Its not popular approach here :) its against Max’ing attitude :D . Since dealing with the coding myself , im patching less for similar reasons , desires and efficiency . But we wont be applaud for this here , its sort of a sin not to wire stuff TOM :)))))))))

May 18 2015 | 8:53 am

A sin! :-o ;-)

Well, "Better to reign in Hell, than to serve in Heaven." Though I’m pretty sure Satan invented the computer mouse…

May 18 2015 | 9:07 am

you mean Douglas Engelbart ? you ingrate :DDDDD

Viewing 12 posts - 1 through 12 (of 12 total)

Forums > Javascript