| 网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 |
![]() |
| Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道 |
Object.prototype.greeting = 'Hello' var o = new Object alert(o.greeting) 网管联盟bitsCN_com
error_reporting(E_ALL);
class Object
{
public static $prototype;
protected function __get($var) {
if ( isset(self::$prototype->$var) ) {
return self::$prototype->$var; }}
} 网管论坛bbs_bitsCN_com
Object::$prototype->greeting = 'Hello'; $o = new Object; echo $o->greeting; // 输出 Hello中国网管联盟bitsCN.com
Object.prototype.say = function(word) { alert(word) }
o.say('Hi') 中国网管联盟bitsCN.com
error_reporting(E_ALL);
class Object
{
public static $prototype;
protected function __get($var) {
if ( isset(self::$prototype->$var) ) {
return self::$prototype->$var; }}
protected function __call($call, $params) {
if ( isset(self::$prototype->$call) && is_callable(self::$prototype->$call) ) {
return call_user_func_array(self::$prototype->$call, $params); }
else {
throw new Exception('Call to undefined method: ' . __CLASS__ . "::$call()"); }}
} 网管下载dl.bitscn.com
Object::$prototype->say = create_function('$word', 'echo $word;');
$o->say('Hi'); 网管网www.bitscn.com
Object.prototype.rock = function() { alert(this.oops) }
o.oops = 'Oops'
o.rock() 网管论坛bbs_bitsCN_com
Object::$prototype->rock = create_function('', 'echo $this->oops;');
$o->oops = 'Oops';
$o->rock(); 网管论坛bbs_bitsCN_com
Object::$prototype->rock = create_function('$caller', 'echo $caller->oops;');
$o->oops = 'Oops';
$o->rock($o); 网管网www_bitscn_com
function create_method($args, $code) {
if ( preg_match('/\$that\b/', $args) ) {
throw new Exception('Using reserved word \'$that\' as argument'); }
$args = preg_match('/^\s*$/s', $args) ? '$that' : '$that, '. $args;
$code = preg_replace('/\$this\b/', '$that', $code);
return create_function($args, $code); } 网管bitscn_com
class Object
{
public static $prototype;
protected function __get($var) {
if ( isset(self::$prototype->$var) ) {
return self::$prototype->$var; }}
protected function __call($call, $params) {
if ( isset(self::$prototype->$call) && is_callable(self::$prototype->$call) ) {
array_unshift($params, $this); // 这里!
return call_user_func_array(self::$prototype->$call, $params); }
else {
throw new Exception('Call to undefined method: ' . __CLASS__ . "::$call()"); }}
} 网管论坛bbs_bitsCN_com
Object::$prototype->rock = create_method('', 'echo $this->oops;');
$o->oops = 'Oops';
$o->rock(); 网管bitscn_com
class Object
{
public static $prototype;
protected function __get($var) {
... }
protected function __call($call, $params) {
... }
}
class Test extends Object
{
}
Test::$prototype->greeting = 'Hello';
print_r(Object::$prototype);
/* outputs
stdClass Object
(
[greeting] => Hello
)
*/
Test::$prototype->say = create_method('$word', 'echo $word;');
$o = new Object;
$o->say('Hi');
/* outputs
Hi
*/ 网管u家u.bitscn@com
|
0
|
评论加载中…