bind this code example

Example 1: $this

<?php
class Test
{
    static public function getNew()
    {
        return new static;
    }
}

class Child extends Test
{}

$obj1 = new Test();
$obj2 = new $obj1;
var_dump($obj1 !== $obj2);

$obj3 = Test::getNew();
var_dump($obj3 instanceof Test);

$obj4 = Child::getNew();
var_dump($obj4 instanceof Child);
?>

Example 2: bind in javascript

bind() returns a bound function that, when executed later, will have the correct context ("this") for calling the original function.

Example 3: javascript bind this syntax

func.bind(this)

Example 4: bind (this)

this.getView().addEventDelegate({
            onBeforeFirstShow: function() {
                // Some codes
            }.bind(this)
        });

Tags:

Php Example