Пример #1
0
 public function testMixin()
 {
     // from js
     __::mixin(array('myReverse' => function ($string) {
         $chars = str_split($string);
         krsort($chars);
         return join('', $chars);
     }));
     $this->assertEquals('aecanap', __::myReverse('panacea'), 'mixed in a function to _');
     $this->assertEquals('pmahc', __('champ')->myReverse(), 'mixed in a function to _ with OO-style call');
     // docs
     __::mixin(array('capitalize' => function ($string) {
         return ucwords($string);
     }, 'yell' => function ($string) {
         return strtoupper($string);
     }));
     $this->assertEquals('Moe', __::capitalize('moe'));
     $this->assertEquals('MOE', __::yell('moe'));
 }
Пример #2
0
<?php

require_once "underscore.php";
__::mixin(['prepend' => function ($string, $to) {
    return !empty($to) && isset($to) ? $string . $to : $string;
}, 'contains' => function ($collection, $value) {
    return __::includ($collection, $value);
}]);