Ning Developer Docs

Here's how to create a proper "constructor" in Javascript. Note that the confusing "new" operator is not required. Also "private variables" are implemented through the magic of closures.

function gizmo(id) {
return {
id: id,
toString: function () {
return "gizmo " +;
From the slides for Douglas Crockford's Advanced Javascript video.

Views: 15


You need to be a member of Ning Developer Docs to add comments!

Join Ning Developer Docs

© 2024   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service