On Wed, Jul 11, 2012 at 4:57 AM, Mike Schwartz <[email protected]> wrote:

> Exposed constructor always throws an error.  document.createElement calls
> an unexposed factory method, which calls a protected constructor.
>

There is a case when a ctor needs to be exposed but should not be invoked
by clients: to allow the use of the "instanceof" operator.

As a concrete example, in my "JSPDO" (PHP PDO clone) i initially hid the
Statement class' constructor from the clients. While writing client-side
code i discovered a need to determine if an object is-a Statement[1] or not
(as opposed to a Object or Array), and ended up having to expose the ctor.
However, i took the draconian steps of explicitly documenting the ctor as
not to be used for anything other than instanceof checks, explicitly did
not document the arguments it takes, and internally intentionally make it
(slightly) difficult for clients to call the ctor (i.e. they'll only know
what to do if they read the C++ code, and if i catch them doing that i'll
change it just to break their script code ;).

Happy Hacking!

[1] = http://code.google.com/p/v8-juice/wiki/JSPDO_API#JSPDO.Statement

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to