JavaScript: typeof - need or new features
Previously there were data of a particular type and there was interestto process them in order to obtain a result. The domination of "atypical ideas in the field of description" came unexpectedly, but naturally. The preliminary declaration of a variable has ceased to be mandatory, and the indication of its type in general has lost all meaning, at least before the operation in which it takes part.
The programmer untied his hands: it is not at all necessary to declare something at the beginning. Often, only by the time of use will there be certainty, what to take, what to do and how. As for types, they themselves "became values", that is, they became data, on which something also depends!
It's still there or not, so what if
A very simple description of the variable "aaa" and the available algorithm for its processing:
var aaa;
if (aaa) {
Res = "I am!"; // I AM!
} else {
Res = "me no ..."; // I do not have
}
will give an obvious result: "I'm not." Here the value of the JavaScript function typeof = undefined. Just describe the variable - "nothing at all" does not mean. Of course, when aaa = 1, we get: "I AM!", But if aaa = 0, it will be like in the first case: "I'm not ...". Wonderful logic, another mathematician, and also a common citizen, could not even think that zero meaning has a completely different meaning than the real one. Only modern (atypical) programming is capable of such bold ideas!
The JavaScript typeof, like the more intelligent expression if (aaa) {... x ...} else {... y ...}, has excellent consumer qualities and is very user-friendly.
On the peculiarities of Cyrillic and Latin
A professional programmer will always preferEnglish mark of the Russian characters, sincerely thanks to that stage of the development of programming, when cybernetics was not recognized on some spaces, but in other territories computer science confidently went uphill. The programming languages began to multiply and develop, taking as a basis the syntax of 26 letters of the English alphabet and a set of other generally accepted symbols.
The simplest and most natural was the machine code,it was beautiful, perfect, but specific to each architecture, and in high-level languages the idea of portability between architectures immediately became relevant. This essentially contradicts the current moment: the grounds for the analogue JavaScript typeof = undefined | string | number | boolean | object | function then simply was not. All languages were strictly formal, had a strict syntax and did not allow uncertainty.
Types, variables and their use
The moment is very important. Typification and description of variables is the most important component of the program, the programmer can not write the working algorithm until he puts the real data variety into a strict formal picture of variables, arrays, objects and functions.
JavaScript carries all the accumulateddecades of functional power, all of its designs perfectly reflect modern ideas about the syntax and expedient rules of putting semantics into it.
The question is, when should this be done, whenit is necessary to define type text, JavaScript typeof function. Actually clean options type text a little: a character, a string and a number. However, the object can play the role of the text, and even an array with the array.join () construct that connects all its elements into a single text, that is, in one line.
Banal statement: all around there is type text, and the JavaScript typeof function must at the right time perform the desired type definition. This is true, but in practice everything turns out differently. The JavaScript typeof object will return the same value in all three cases:
var aaa = {};
Res = typeof(aaa);
Res + = "/" + typeof window.document;
Res + = "/" + typeof(document.forms[0]);
result: object / object / object
The use of the function can be in the format typeof (aaa) and format typeof aaa - this is not essential, but in all cases the answer is given, but it does not mean anything at all!
Uncertainty passes into certainty
Programming is characterized by a special dynamics: it so rapidly flies forward that the scale of motion is continuously expanding. The account goes for months, weeks or days, and sometimes even for hours. In specific problems, the dynamics of the solution algorithm formation is so fast and demanding to continuity that the programmer's exit from the working state can discard the decision for a day, a week and a longer period.
A natural solution of JavaScript typeof and practiceobject-oriented programming, which in this syntax is slightly different from the existing in adjacent modern languages, transfers the center of gravity to the object. A very characteristic moment: language becomes a construction containing semantics, and not a set of syntactic norms.
Simple data types do not need to be definedits type, or rather the use of JavaScript typeof is enough. If necessary, the runtime itself takes care of the proper transformations, but with respect to JavaScript objects typeof gives the most reasonable answer: it is an object and the problem of its type is its care! Such logic for the classical view of programming is difficult to perceive, but this is the real position of the right things.
Caring for an object - to determine your type, to showtheir properties and perform their own methods. Programming polished its syntax and with each moment of time transfers the center of gravity from the syntax to the semantics formed by the programmer: the system of its objects that perform the solution of the task.