Closed ghost closed 11 years ago
The idea of this project is to convert PHP into equivalent Javascript. If you then need to do extra stuff in Javascript e.g. like binding objects to events, you should do that in a separate Javascript file that does the binding of the Javascript converted from PHP to the events.
However even if you really do want to do it all in one file, there's a better way of doing it. Using the:
$phpToJavascript->addPostConversionReplace("//JS", "");
To allow us to insert actual Javscript into the PHP, we can do:
class TestClass {
public $message;
function __construct($message) {
$this->message = $message;
}
function windowCloseFunction() {
echo "Goodbye ".$this->message;
}
//If you have jQuery
//JS window.onresize = $.proxy(this, 'windowCloseFunction');
//Or with standard Javascript
// //JS this.makeWindowCloseFunction = function($context, $functionName) {
// //JS return function() {
// //JS $functionName.call($context);
// //JS }
// //JS}
// //JS
// //JS window.onresize = this.makeWindowCloseFunction(this, this.windowCloseFunction);
}
$test = new TestClass("cruel world!");
I know that a lot of tutorial say to use a var
to save the current context - I'm pretty sure that's a bad idea.
var is useful keyword in js. see
I think php var, like