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 " + this.id;
}
};
}
From the slides for Douglas Crockford's Advanced Javascript video.

Views: 9

Comment

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

Join Ning Developer Docs

© 2019   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service