Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ansimuz

Hi,

For the sake of readabilty of my project, its there a way to include external functions into the main.js?

for example i want to have a file with common functions and i want them to include them as an external file. What would be the best approach.

thanks

1 decade ago by taddeimania

I've done something very similar with a utility object that gives me pluggable functionality. Here is an example of a very scaled down approach.

https://github.com/taddeimania/impactjs-memorypuzzle/blob/master/lib/game/utility.js

Then in my main.js I do this:

https://github.com/taddeimania/impactjs-memorypuzzle/blob/master/lib/game/main.js

Line #8 to include it

Line #43 to instantiate it on the game

Line #87 to call the shuffle method.

1 decade ago by Graphikos

You could always just include them as their own .js file not part of the class system.

	<script type="text/javascript" src="lib/impact/impact.js"></script>
	<script type="text/javascript" src="lib/impact/your_functions.js"></script>
	<script type="text/javascript" src="lib/game/main.js"></script>

1 decade ago by ansimuz

@tadeimania

Thats exactly what i need thanks for the detailed explaination.

@graphikos

Seems elegant but i suppose that i cannot bake it, right?

1 decade ago by Graphikos

@ansimuz

I hadn't really considered baking which probably requires files define a module and therefore wouldn't work with the included baking script. You could probably minify it yourself and tack it in manually though.

taddeimania's method is how I'd do it also but I wanted to point out that this is all just Javascript and nothing prevents you from pulling in other scripts. Same idea that you could pull in other libs like jQuery and use that in impact if you wanted to.

1 decade ago by taddeimania

Quote from Graphikos
this is all just Javascript and nothing prevents you from pulling in other scripts. Same idea that you could pull in other libs like jQuery and use that in impact if you wanted to.


very relevant point and important to not forget this.
Page 1 of 1
« first « previous next › last »