Brought to you by LEAP™ 5 and Lasso 9

Protecting Lasso and JavaScript from one another

I got asked recently about how to use Lasso and JavaScript together, and while it's a technique we've been coping with for years it's one of those things we just assume people know and therefore it's not "out there" in the public domain as to how.

Lasso can use square brackets for including code in HTML, and yet JavaScript uses square brackets for arrays. 

The problem is at the server end: the client-side JavaScript "var x = myArray[myNum]" should return the element of integer value "mynum" in the array "myArray", and yet Lasso will try to evaluate the square brackets, producing an error (likely saying no tag, type or constant named myNum has been defined - the exact error will vary depending on version of Lasso).

[noprocess]

The [noprocess] code block will prevent Lasso from processing anything contained within. Great brute-force approach. To be honest, while it's effective it's not really a favourite. It's noisy and the equivalent of attacking your laptop with a sledgehammer. Not pretty.

Docs can be found at: http://www.lassosoft.com/lassoDocs/languageReference/obj/NoProcess

<script>
[noprocess]
	var x = new Array;
	x[0] = 11;
	x[1] = 22;
	for(i=0;i<x.length;i++) {
		document.write('<p>x as array pos 1 = '+x[i]+'</p>');
	}
[/noprocess]
</script>

 

Use HTML comments

Arguably simpler is the use of HTML comments inside the JavaScript. It's more elegant and gets picked up better in syntax colouring of all the major code editors. It also helps to visually identify areas when looking at the generated source code. This is my favourite method for general code.

<script>
// <!--
	var x = new Array;
	x[0] = 11;
	x[1] = 22;
	for(i=0;i<x.length;i++) {
		document.write('<p>x as array pos 1 = '+x[i]+'</p>');
	}
// -->
</script>

 

[no_square_brackets]

The coolest irony in Lasso 9. To turn off the Lasso 9 parser's affinity for square brackets, put this at the top of the file. Here's the irony: [no_square_brackets] must be the first thing in the file (with no white spece before even!), and is the only thing in that file to be processed in square brackets!.

From that moment on, square brackets are ignored by the Lasso 9 parser & compiler.

To invoke [date] then, you would use .

[no_square_brackets]
<h1><?lasso date ?></h1>

<script>
	var x = new Array;
	x[0] = 11;
	x[1] = 22;
	for(i=0;i<x.length;i++) {
		document.write('<p>x as array pos 1 = '+x[i]+'</p>');
	}
</script>

 

Docs for [no_square_brackets] can be found here: 
http://www.lassosoft.com/lassoDocs/languageReference/obj/no_square_brackets

 

comments powered by Disqus