JavaScript DHTML/Mochkit/instanceof

Материал из Web эксперт
Перейти к: навигация, поиск

instanceof operator

   <source lang="html4strict">


<html> <head>

   <script type="text/javascript" src="MochiKit-1.4.2/lib/MochiKit/Base.js"></script>
   <script type="text/javascript" src="MochiKit-1.4.2/lib/MochiKit/Iter.js"></script>
   <script type="text/javascript" src="MochiKit-1.4.2/lib/MochiKit/DOM.js"></script>
   <script type="text/javascript" src="MochiKit-1.4.2/lib/MochiKit/Style.js"></script>
   <script type="text/javascript" src="MochiKit-1.4.2/lib/MochiKit/Logging.js"></script>
   <script type="text/javascript" src="MochiKit-1.4.2/lib/MochiKit/Iter.js"></script>

</head> <body>

<script type="text/javascript">
    var O = function (value) {
        bindMethods(this);
        this.value = value;
    };
    O.prototype.func = function () {
        return this.value;
    };
    var o = new O("boring");
    var p = {};
    p.func = o.func;
    var func = o.func;
    alert( o.func(), "boring", "bindMethods doesn"t break shit" );
    alert( p.func(), "boring", "bindMethods works on other objects" );
    alert( func(), "boring", "bindMethods works on functions" );
    var p = clone(o);
    alert( p instanceof O, "cloned correct inheritance" );
    var q = clone(p);
    alert( q instanceof O, "clone-cloned correct inheritance" );
    q.foo = "bar";
    alert( p.foo, undefined, "clone-clone is copy-on-write" );
    p.bar = "foo";
    alert( o.bar, undefined, "clone is copy-on-write" );
    alert( q.bar, "foo", "clone-clone has proper delegation" );
    // unbind
    p.func = bind(p.func, null);
    alert( p.func(), "boring", "clone function calls correct" );
    q.value = "awesome";
    alert( q.func(), "awesome", "clone really does work" );
</script>

</body> </html>

 </source>