小编FTa*_*Tav的帖子

使用VBA提取Word文档的目录的标题和页面编号

基本上我们在这里有什么

从Word文档中获取标题

Public Sub CreateOutline()
    Dim docOutline As Word.Document
    Dim docSource As Word.Document
    Dim rng As Word.Range

    Dim astrHeadings As Variant
    Dim strText As String
    Dim intLevel As Integer
    Dim intItem As Integer

    Set docSource = ActiveDocument
    Set docOutline = Documents.Add

    ' Content returns only the
    ' main body of the document, not
    ' the headers and footer.
    Set rng = docOutline.Content
    astrHeadings = _
     docSource.GetCrossReferenceItems(wdRefTypeHeading)

    For intItem = LBound(astrHeadings) To UBound(astrHeadings)
        ' Get the text and the level.
        strText …
Run Code Online (Sandbox Code Playgroud)

vba ms-word word-vba

7
推荐指数
1
解决办法
7418
查看次数

Javascript数组/函数对象的引用

鉴于:

function shout(){ alert('Hello!'); }
var dasarray = [ shout ];

shout();
dasarray[0]();

shout = function(){ alert('World!'); }

shout();
dasarray[0]();
Run Code Online (Sandbox Code Playgroud)

输出:

Hello!

Hello!

World!

Hello!
Run Code Online (Sandbox Code Playgroud)

我本来期望dasarray收到对该函数的引用shout,但遗憾的是第4个输出也是你好.如果我假设正确,我能够shout正确地修改函数,但这导致我假设函数没有通过引用传递给dasarray.

我已经用一个对象尝试了这个例子而不是一个数组:

dasarray = { myfunction: shout }
Run Code Online (Sandbox Code Playgroud)

同样,令人失望的结果.

我的目的是拥有/带有函数的数组/对象,它们按顺序运行并且可以实时扩展.例如,使用新功能扩展javascript并向正确顺序运行的现有事件添加其他函数调用.

那么,任何想法如何通过引用将函数放入数组/对象?


编辑:谢谢你的好答案.我只是想解释一下,我选择了Eli的答案,因为它引导我进入这个设置:

zzz = {
    calls: [],
    shout: function(message) {
        alert('Shouting: ' + message);
    },
    initialize: function () {
        zzz.calls.push(['shout','Hello World']);
        zzz.calls.push(['shout','this is']);
        zzz.calls.push(['shout','my last shout!']);
        zzz.run();

        zzz.shout = function(){ alert('modified!'); };
        zzz.run();
    },
    run: function () …
Run Code Online (Sandbox Code Playgroud)

javascript arrays function object pass-by-reference

3
推荐指数
1
解决办法
2268
查看次数