Pseudo-classical vs. "The JavaScript way" -


Reading of Crockford's " " has ended and I have a question that relates to my attitude on psuedo-classical.

vs prototype approach Actually I am not really interested in your stand; I just want to understand my reasoning, so I can set my own stance.

In the book, Crockford is estimating the work of that constructor and "all jazz" should not be used in Javascript, he mentions how the 'new' keywords are applied badly - Non-constructor functions can be called with 'new' keywords and vice versa (possibly causing problems).

I thought I understood where he was coming from but I think that I do not.

When I need to create a new module, I will usually start this way:

  function MyModule (some) {this.something = some || {}; }  

And then I will add some methods to my prototype:

  MyModule.prototype = {setSomething: function () {}, getSomething: function () {}, DoSomething: function () {}}  

I like this model; This means that whenever I need one, and he can make a new example of his possessions and methods:

  var foo = new MyModule ({option1: 'bar' }); // fu is an object; I can do anything for this; All the methods of "class" // are available for this example  

My question is : How can I get the above using a more appropriate approach to javascript? In other words, if "javascript" was a person, what would he suggest?

Besides: What does Crockford mean when he says that a special design pattern is "more expression" then the other?

See:

It is important to remember that Crockford, so many JavaScript programmers Like before, it is a language that looks at "fixing" - making it like other (so-called "classical") OO languages, structural codes were written in large amounts, libraries and frameworks were made, and .. So they came to know that it was not really necessary; If you contact JS on your terms, you can meet with them properly.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -