1. Embed php code in javascript
If javascript is included through a js file, then php code can also be written directly in the js file. However, if the js file is included, the extension must be changed to php, such as:
2. Default values of javascript function parameters
In C language, you can set default parameters like this:
void foo(int a, int b = 1, bool c = false);
But javascript cannot do this:
newGame: function(a, b = 0)
ie and chrome will report an error, and ff will directly ignore it.
We can use the arguments read-only variable array to achieve this:
function newGame(){
var a = arguments[0] ? arguments[0] : 1;
var b = arguments[1] ? arguments[1] : false;
//Function content
}