I would avoid the "new" here and just go for:
nc = (function () {
// code in here
}());

Regarding the original question (difference between prototype and instance methods) - does anyone have a good article explaining what the pros/cons for each approach are? I think I know them but would love to be pointed to a blog post that discusses them in more detail.

Best,
Marko

Discussion of JavaScript wrote:
If you want to call nc methods within the nc object scope, you can create it as a singleton:

var nc = new function() {
    // anthing in here is private access for you
    var privateVar = 'foo';

    return {

        // and anything in here is publicly available
            publicVar: 'bar',
            alert: function(obj) {
alert(privateVar + ' ' + this.publicVar + ' - ' + obj.msg);
            }
    }
}();

...
nc.alert({ msg: 'alrightly then...' });
...

Casey


On 06/12/2010 07:53, Discussion of JavaScript wrote:
Hi all,

Please help me with this object I created for just calling a function.

var nc = nc || {};

nc = {
  alert: function(obj){
    alert(obj);
} };

So, when I call it will become like nc.alert({ id:0 });

I want to create a global function within my system. So, I made 'nc' object to make more sense and standard function to my system. The question , 1. should I apply the prototype to the object nc? 2. or.. this 'nc' object I created is sufficient enough to call a function within 'nc' object scope?

Thank you.

--
Best Regards,
Hudz


_______________________________________________
JSMentors mailing list
JSMentors@jsmentors.com
http://jsmentors.com/mailman/listinfo/jsmentors_jsmentors.com
------------------------------------------------------------------------

_______________________________________________
JSMentors mailing list
JSMentors@jsmentors.com
http://jsmentors.com/mailman/listinfo/jsmentors_jsmentors.com

_______________________________________________
JSMentors mailing list
JSMentors@jsmentors.com
http://jsmentors.com/mailman/listinfo/jsmentors_jsmentors.com

Reply via email to