[svn openjsan.org] [464] Added note about canOK() and classes with prototypes constructed from anonymous objects.

0 views
Skip to first unread message

ca...@geeknest.com

unread,
Sep 8, 2005, 8:01:23 PM9/8/05
to jsan-...@googlegroups.com
Revision: 464
Author: theory
Date: 2005-09-08 20:01:12 -0400 (Thu, 08 Sep 2005)

Log Message:
-----------
Added note about canOK() and classes with prototypes constructed from anonymous objects.

Modified Paths:
--------------
users/theory/Test.Simple/trunk/Changes
users/theory/Test.Simple/trunk/doc/pod/Test/More.pod
users/theory/Test.Simple/trunk/lib/Test/More.js
Modified: users/theory/Test.Simple/trunk/Changes
===================================================================
--- users/theory/Test.Simple/trunk/Changes 2005-09-08 19:56:18 UTC (rev 463)
+++ users/theory/Test.Simple/trunk/Changes 2005-09-09 00:01:12 UTC (rev 464)
@@ -1,6 +1,8 @@
Revision history for JavaScript class Test.Simple.

0.22
+ - Added note to the documentation of "canOK()" explaining why it doesn't
+ work for objects based on prototypes created from anonymous classes.

0.21 2005-08-29T17:16:33
- Moved source code to JSAN Subversion repository. Check it out at

Modified: users/theory/Test.Simple/trunk/doc/pod/Test/More.pod
===================================================================
--- users/theory/Test.Simple/trunk/doc/pod/Test/More.pod 2005-09-08 19:56:18 UTC (rev 463)
+++ users/theory/Test.Simple/trunk/doc/pod/Test/More.pod 2005-09-09 00:01:12 UTC (rev 464)
@@ -336,6 +336,34 @@
canOK('Foo', meth);
}

+B<Note:> Instances of classes defined by assigning anonymous objects to the
+C<prototype> attribute of the constructor will not work properly in the
+C<canOK()> function.
+
+ My.Class = function () {};
+ My.Class.prototype = {
+ foo: function () { return 'foo' },
+ bar: function () { return 'bar' }
+ };
+
+ var my = new My.Class();
+ canOK(my, 'foo'); // Fail
+
+This is because the anonymous object assigned to the prototype is constructed
+by the base C<Object> class, not by the C<My.Class()> construtor. The
+workaround is to call C<canOK()> with the class name, instead:
+
+ canOK('My.Class', 'foo'); // Pass
+
+This is not an issue for prototypes that are simply assigned to:
+
+ My.Class = function () {};
+ My.Class.prototype.foo = function () { return 'foo' };
+ My.Class.prototype.bar = function () { return 'bar' };
+
+ var my = new My.Class();
+ canOK(my, 'foo'); // Pass
+
=item B<isaOK>

isaOK(object, class, objectName);

Modified: users/theory/Test.Simple/trunk/lib/Test/More.js
===================================================================
--- users/theory/Test.Simple/trunk/lib/Test/More.js 2005-09-08 19:56:18 UTC (rev 463)
+++ users/theory/Test.Simple/trunk/lib/Test/More.js 2005-09-09 00:01:12 UTC (rev 464)
@@ -89,7 +89,7 @@
if (typeof proto[method] != 'function') nok.push(method);
}

- // There'es no can() method in JavaScript, but what the hell!
+ // There's no can() method in JavaScript, but what the hell!
var desc = clas + ".can('" + (arguments.length == 2 ? arguments[1] : '...') + "')";
ok = Test.More.Test.ok(!nok.length, desc);
for (var i = 0; i < nok.length; i++) {



Reply all
Reply to author
Forward
0 new messages