If I were shown these lines and asked to say “what the hell is this”, I would spend more than one minute to figure it out :) This is what gives the supporter JS so much strength in the statement that class-based languages ​​lead to excessive when writing code Programmers focus on hierarchy and class relationships with each other, which in my opinion is true.function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
function bicubic(count) { var values = []; for ( var i = 0; i < count; i++) { values[i] = ( function (n) { return function () { return Math.pow(n, 3); } } )(i); } return values; } var vals = bicubic(10); alert( vals[3]() ); * This source code was highlighted with Source Code Highlighter .
In prototype-oriented systems (for example, JS), two methods are provided for creating a new object: cloning an existing object, or creating an object from scratch . To create an object from scratch, the programmer is provided with syntactic means of adding properties and methods to the object. Further, a complete copy of the clone can be obtained from the resulting object. In the process of cloning a copy inherits all the characteristics of its prototype, but from that moment it becomes independent and can be changed. In some implementations, copies store references to prototype objects, delegating to them some of their functionality; however, the prototype change may affect all copies. In other implementations, new objects are completely independent of their prototypes.Demonstration:
* This source code was highlighted with Source Code Highlighter .
- function win () {
- this .open = function ()
- {
- return "open 1" ;
- }
- }
- win.open = function () {
- return "open 2" ;
- }
- alert (win.open ()); // 1. open 2
- win.prototype = {
- save: function ()
- {
- return "open 3" ;
- }
- }
- alert (win.save ()); // 2. error - no save
- win.prototype.open = function ()
- {
- return "open 4" ;
- }
- alert (win.open ()); // 3. open 2
- var vista = new win ();
- alert (vista.open ()); // 4. open 1
- alert (vista.save ()); // 5. open 3
- vista.open = (
- function ()
- {
- return "open 5" ;
- }
- ) ();
- alert (vista.open); // 6. open 5
- alert (win.open ()); // 7. open 2
Creating an object "from scratch" in JS, "this thing"! I will give an example that helps save the muscular efforts of the fingers:* This source code was highlighted with Source Code Highlighter .
- function win ()
- {
- var str = "open 1" ;
- this .open = function ()
- {
- return str;
- }
- }
- alert (( new win ()). open ()); // open 1
* This source code was highlighted with Source Code Highlighter .
- function plugin (options)
- {
- options = options || {};
- options.list = options.list || [];
- // then you can safely work
- // options, check its properties, for example,
- // a with list as with an array
- }
It is very difficult to find a black cat in a dark room, especially if it is not there :)
© folk wisdom
Source: https://habr.com/ru/post/49772/
All Articles