Exemple #1
0
    $self = Func::getContext();
    $args = func_get_args();
    return $self->apply($args[0], array_slice($args, 1));
}, 'apply' => function ($context, $args = null) {
    $self = Func::getContext();
    if ($args === null) {
        $args = array();
    } else {
        if ($args instanceof Args || $args instanceof Arr) {
            $args = $args->toArray();
        } else {
            throw new Ex(Error::create('Function.prototype.apply: Arguments list has wrong type'));
        }
    }
    return $self->apply($context, $args);
}, 'toString' => function () {
    $self = Func::getContext();
    $source = array_key_exists('source_', $GLOBALS) ? $GLOBALS['source_'] : null;
    if ($source) {
        $meta = $self->meta;
        if (isset($meta['id']) && isset($source[$meta['id']])) {
            $source = $source[$meta['id']];
            return substr($source, $meta['start'], $meta['end'] - $meta['start'] + 1);
        }
    }
    return 'function ' . $self->name . '() { [native code] }';
});
Func::$protoObject = new Object();
Func::$protoObject->setMethods(Func::$protoMethods, true, false, true);
//set the methods on Object.prototype before we proceed
Object::$protoObject->setMethods(Object::$protoMethods, true, false, true);