Transferring objects in the window.setTimeout method_javascript tips
The syntax is:
window.setTimeout(expr,msec)
expr is the execution string, and after msec milliseconds, it will be run as js. I just discovered yesterday that expr can also be a function. Haha, using this feature, objects can be transferred.
The following code implements the function of delayed transmission of object p in function foo1 to function foo2.
[Ctrl A to select all Note: If you need to introduce external Js, you need to refresh to execute
If you need to introduce external Js, you need to refresh To execute
][Ctrl A Select all Note:
If you need to introduce external Js needs to be refreshed to execute
]
Many frameworks now actually directly use a multi-cast event (its implementation principle is not complicated). A multi-cast event itself is actually a standard function. But it generally has the following methods.
MuEvent.add = function (func) { ... }
MuEvent.addMethod = function (instance, func) { ... }
When using the first method, when activating the func event processing function, use the current instance of MuEvent as this object; the second method uses the incoming instance as this object.
So for setTimeout, our traditional method is to use it to activate the method like this:
----------
function doTimer() {
obj1.call();
obj2.call();
}
setTimeout(doTimer, 1000);
and use multi-cast events The code can be as follows:
----------
var e = new MuEvent();
e.addMethod(obj1, obj1.call);
e.addMethod(obj2, obj2.call);
setTimeout(e, 1000);
----------
Of course , if you want to write more COOL, you can do it like this:
----------
setTimeout(function() {
return new MuEvent (obj1, obj1.call, obj2, obj2.call);
}(), 1000); <script> foo1() function foo1(){ var p={x:3,y:4} window.setTimeout(function(){foo2(p)},100) } function foo2(p){ alert(p.x) } </script>---------- <script> foo1() function foo1(){ var p={x:3,y:4} window.setTimeout(function(){foo2(p)},100) } function foo2(p){ alert(p.y) //输出foo1的p={x:3,y:4} 的y } </script><script> var pp=3; foo1() function foo1(){ var p={x:3,y:4} var pp=1; window.setTimeout(function(){foo2('pp')},100) window.setTimeout("(function(){foo2("+pp+")})()",200) //也就是说,这个函数其实将参数值传过去.相当于如下将foo2引用进来运行: window.setTimeout("(function(){alert("+pp+")})()",200) } function foo2(pp){ alert(pp) var pp=2; alert(pp) } </script>As a little introduction , the Qomo I made is MuEvent implemented in this form. Most frameworks like Atlas adopt a similar approach.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
