创建代码以逐个运行函数(DOM)的一些想法

Some ideas to create a code to run functions one after another (DOM)

本文关键字:DOM 代码 函数 运行 创建      更新时间:2023-09-26

我有一些函数来操作DOM。一个创建一些css样式,另一些创建一些html元素,然后再创建一些css等等(例如7-8步)

每个函数或多或少都依赖于前一个函数。需要一种回调方法。

我知道如何创建购买,我想要一些类似的函数(避免手动编写回调调用)

My_dom_auto.add (function () {} ); // 1
My_dom_auto.add (function () {} ); // 2
My_dom_auto.add (function () {} ); // 3
My_dom_auto.run ();

My_dom_auto.add将把接收到的函数封装到一个新函数中,类似于以下内容:

My_dom_auto.add = fucntion (original_function_code) {
 fake_function.push (
     original_funcion_code_coied_line_by_line ;
     My_dom.internal_function()
}
} 

所以我可以调用fake_functions。。。

问题是。。。。能做到吗?怎样使用函数Object?另外如何在函数中注入新的最后一行?

你觉得怎么样?任何想法都将不胜感激。

我认为使用Stack(抽象数据类型)会很有用

使用数组来推送函数(cssStyle_1->HtmlElement_1->cssStyle_2->HtmlElement _2->…)

然后弹出功能并一个接一个地执行

a= function(){console.log("1") }
b= function(){console.log("2") }
c= function(){console.log("3") }
tab = []
tab.push(a)
tab.push(b)
tab.push(c)
tab.pop()
// 3
tab.pop()
// 2
tab.pop()
// 1