From 980fe00a74a9ad013b945755415ace2e5429c3c2 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Wed, 27 Oct 2021 02:31:24 +0300 Subject: [RU] Remove notranslate (#2874) --- files/ru/web/api/settimeout/index.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'files/ru/web/api/settimeout') diff --git a/files/ru/web/api/settimeout/index.html b/files/ru/web/api/settimeout/index.html index 5c4cb67a3b..6e38955b9f 100644 --- a/files/ru/web/api/settimeout/index.html +++ b/files/ru/web/api/settimeout/index.html @@ -12,7 +12,7 @@ original_slug: Web/API/WindowOrWorkerGlobalScope/setTimeout

Синтаксис

-
var timeoutID = window.setTimeout(func, [, delay, param1, param2, ...]);
+
var timeoutID = window.setTimeout(func, [, delay, param1, param2, ...]);
 var timeoutID = window.setTimeout(code [, delay]);
 
@@ -35,7 +35,7 @@ original_slug: Web/API/WindowOrWorkerGlobalScope/setTimeout

HTML Content

-
<p>Live Example</p>
+
<p>Live Example</p>
 <button onclick="delayedAlert();">Show an alert box after two seconds</button>
 <p></p>
 <button onclick="clearAlert();">Cancel alert before it happens</button>
@@ -43,7 +43,7 @@ original_slug: Web/API/WindowOrWorkerGlobalScope/setTimeout
 
 

JavaScript Content

-
var timeoutID;
+
var timeoutID;
 
 function delayedAlert() {
   timeoutID = window.setTimeout(slowAlert, 2000);
@@ -66,7 +66,7 @@ function clearAlert() {
 
 

Если вам нужно передать аргумент в вашу callback функцию, но нужно, чтобы это работало в Internet Explorer 9 и ниже, который не поддерживает передачу дополнительных параметров (ни с setTimeout() или setInterval()), то вы можете прописать специальный код для совместимости с IE, вставив этот код в начало ваших скриптов, который включит функцию передачи стандартных параметров HTML5 в Internet Explorer для обоих таймеров.

-
/*\
+
/*\
 |*|
 |*|  IE-specific polyfill which enables the passage of arbitrary arguments to the
 |*|  callback functions of JavaScript timers (HTML5 standard syntax).
@@ -108,7 +108,7 @@ if (document.all && !window.setInterval.isPolyfill) {
 
 

If you want a completely unobtrusive hack for every other mobile or desktop browser, including IE 9 and below, you can either use JavaScript conditional comments:

-
/*@cc_on
+
/*@cc_on
   // conditional IE < 9 only fix
   @if (@_jscript_version <= 6)
   (function(f){
@@ -121,7 +121,7 @@ if (document.all && !window.setInterval.isPolyfill) {
 
 

Или используйте очень чистый подход, основанный на условном свойстве IE HTML:

-
<!--[if lte IE 9]><script>
+
<!--[if lte IE 9]><script>
 (function(f){
 window.setTimeout =f(window.setTimeout);
 window.setInterval =f(window.setInterval);
@@ -133,12 +133,12 @@ var a=[].slice.call(arguments,2);return f(function(){c.apply(this,a)},t)}
 
 

Another possibility is to use an anonymous function to call your callback, but this solution is a bit more expensive. Example:

-
var intervalID = setTimeout(function() { myFunc("one", "two", "three"); }, 1000);
+
var intervalID = setTimeout(function() { myFunc("one", "two", "three"); }, 1000);
 

Yet another possibility is to use function's bind. Example:

-
setTimeout(function(arg1){}.bind(undefined, 10));
+
setTimeout(function(arg1){}.bind(undefined, 10));
 

Проблема с "this"

@@ -149,7 +149,7 @@ var a=[].slice.call(arguments,2);return f(function(){c.apply(this,a)},t)}

Code executed by setTimeout() is run in a separate execution context to the function from which it was called. As a consequence, the this keyword for the called function will be set to the window (or global) object; it will not be the same as the this value for the function that called setTimeout. See the following example:

-
myArray = ["zero", "one", "two"];
+
myArray = ["zero", "one", "two"];
 myArray.myMethod = function (sProperty) {
     alert(arguments.length > 0 ? this[sProperty] : this);
 };
@@ -168,7 +168,7 @@ setTimeout.call(myArray, myArray.myMethod, 2500, 2); // same error

A possible way to solve the "this" problem is to replace the two native setTimeout() or setInterval() global functions with two non-native ones which will enable their invocation through the Function.prototype.call method. The following example shows a possible replacement:

-
// Enable the passage of the 'this' object through the JavaScript timers
+
// Enable the passage of the 'this' object through the JavaScript timers
 
 var __nativeST__ = window.setTimeout, __nativeSI__ = window.setInterval;
 
@@ -190,7 +190,7 @@ window.setInterval = function (vCallback, nDelay /*, argumentToPass1, argumentTo
 
 

Новая тестируемая особенность:

-
myArray = ["zero", "one", "two"];
+
myArray = ["zero", "one", "two"];
 myArray.myMethod = function (sProperty) {
     alert(arguments.length > 0 ? this[sProperty] : this);
 };
@@ -214,7 +214,7 @@ setTimeout.call(myArray, myArray.myMethod, 2500, 2); // prints "two" after 2.5 s
 
 

Передача строки вместо функции в setTimeout() сопряжена с теми же опасностями, что и использование eval.

-
// Правильно
+
// Правильно
 window.setTimeout(function() {
     alert("Hello World!");
 }, 500);
-- 
cgit v1.2.3-54-g00ecf