Change - JavaScript

Created on Feb. 7, 2013, 1:35 p.m. by Hevok & updated on Feb. 7, 2013, 1:36 p.m. by Hevok

JavaScript is an interpreted Programming Language that was originally implemented as part of Web browsers in order that client-side scripts can interact with the user, control the browser, communicate asynchronously and alter document Content that is displayed. ¶
¶
In JavaScript Syntax variables are declared like RenderEngineClass below. Variables are defined by starting with the keyword var. ¶
¶
.. sourcecode:: js ¶
¶
// Declaring a JavaScript object using literal notation ¶
var RenderEngineClass = { ¶
¶
// Declaring a method of an object ¶
drawString: function (pString, pFontName, locX, locY, size, settings) { ¶
¶
// Declaring a variable and assinging to it: ¶
var ctx = gRenderEngine.context; ¶
¶
// Accessing the member property 'font' of the 'ctx' object. ¶
// Also shows the '+' operator overloaded to do string concatenation: ¶
ctx.font = size + "pt " + pFontName; ¶
¶
// Single-line if block doesn't require surrounding braces: ¶
if(settings.color) ctx.fillStyle = settings.color; ¶
¶
// Multi-line if blocks DO require surrounding braces: ¶
if(settings.color) { ¶
¶
var maxWidth = settings.bounds.w; ¶
¶
// Calling the 'split' method of the 'pSpring' object. ¶
var words = pString.split(" "); ¶
var line = ""; ¶
var lineHeight = size + 4; ¶
var = locY; ¶
¶
// for statements are syntactically similarly to C: ¶
for(var n = 0; n < words.length; n+) { ¶
¶
// Accessing the nth character in the 'words' string. ¶
// All lists work similarly. ¶
var testLine = line + words[n] + " "; ¶
var metrics ctx.measureTest(testline): ¶
var testWidth = metrics.width; ¶
if(settings.bounds) { ¶
¶
ctx.fillText(line, locX, y); ¶
line = word[n] + " "; ¶
y += lineHeight; ¶
// else statements can go on the same line as the ¶
// closing brace of the preceding if statement, but ¶
// they do not have to. ¶
} else { ¶
line = testLine; ¶
} ¶
} ¶
¶
ctx.fillText(line, locX, y); ¶
¶
} else { ¶
¶
if(settings.borderColor) { ¶
¶
// Single-line if block ¶
} ¶
¶
JavaScript provides a way to define a set of variables and functions and to encapsulate them as an object, called a prototype. ¶
¶
¶
Classes ¶
------- ¶
Object-orientated set up can by emulated with JavaScript. ¶
¶
An inheritance tree can be created by using Class.extend() of the following form: ¶
¶
1. Weapon extends Class ¶
2. MachineGun extends Weapon ¶
3. ChainGun extends Weapon ¶
4. Entity extends Class ¶
5. Teleporter extends Entity ¶
6. EnergyCanister extends Entity ¶
¶
.. sourcecode:: js ¶
¶
Weapon = Class.extend({ ¶
init: function() { ¶
¶
} ¶
}); ¶
¶
MachineGun = Weapon.extend({ ¶
init: function() { ¶
¶
} ¶
}); ¶
¶
ChainGun = Weapon.extend({ ¶
init: function() { ¶
¶
} ¶
}); ¶
¶
Entity = Class.extend({ ¶
init: function() { ¶
¶
} ¶
}); ¶
¶
Teleporter = Entity.extend({ ¶
init: function() { ¶
¶
} ¶
}); ¶
¶
EnergyCanister = Entity.extend({ ¶
init: function() { ¶
¶
} ¶
}); ¶
¶
Resources ¶
--------- ¶
* Web platf
rorm [http://docs.webplatform.org] ¶
* Mozilla Developer Network [http
s://developer.mozilla.org/en-US/]


Comment: Corrected resoruces links.

Comment on This Data Unit