javascript - When developing OOJS, should I reference the protoype function, or the variables version? -
Specify the title (type), when I am prototyping in JS, and I refer to its second function Need to provide the object, can I use its protonal version, or local variable version? Are there any issues related to either (major) overhead or one?
// start foo = function () {} Foo.prototype.ShowMessage = function (msg) {alert}; } // Method 1 Foo.prototype.Validate = function (msg) {// Some verification materials ... if (! Valid) {this.ShowMessage ("Please check your input, they are having problems with them." ); }} // Method 2 Foo.prototype.Validate = Function (msg) {// Some verification material ... if (valid!) {Foo.prototype.ShowMessage ("Please check your input, there is a problem in them. "); }}
I would like method 1, purely because it's easy to type instead of fu.prototype, but is it a fair demonstration? Or am I just talking about this?
You should definitely use it
this.showMessage ( "message");
The second version will not work perfectly. Why? As a result of that launch of showMessage
, this "variable" will not be the result of the prototype object and not the example. It will almost certainly not happen that you want.
Comments
Post a Comment