使用htmlfile COM对象访问WSH JScript中对象的.getOwnPropertyDescriptor()方法 [英] Using htmlfile COM object to access the .getOwnPropertyDescriptor() method of an object in WSH JScript

查看:88
本文介绍了使用htmlfile COM对象访问WSH JScript中对象的.getOwnPropertyDescriptor()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的评论中,我被告知.getOwnPropertyDescriptor()方法

In the comments of this question, I was told that the .getOwnPropertyDescriptor() method

ES3不支持

...,因此JScript [两个]都可能不支持

isn't supported in ES3 ..., so it probably isn't supported in JScript [either]

,这确实是我尝试在cscript.exe/wscript.exe中调用该方法时看到的内容:

and that is indeed what I see when trying to invoke that method in cscript.exe/wscript.exe:

对象不支持此属性或方法

Object doesn't support this property or method

但是,我正在使用的最新JScript版本是5.812,并且根据本文档,该方法应该在5.8* JScript中可用. 这篇文章中也指出了差异,指向

However, the latest JScript version I'm using is 5.812 and according to this document, the method should be available in 5.8* JScript. The discrepancy has also been noted in this post, pointing towards another post where a workaround using htmlfile COM object has been provided to access the missing properties/methods in Windows Script Host (WSH) JScript.

我想知道是否有可能使用WSH JScript来使用相同的方法来访问上述方法.

I was wondering if it is possible to use the same method to access the above method is WSH JScript as well.

例如,代码应类似于

var object1 = {
  property1: 42
};

var htmlDoc = WScript.CreateObject('htmlfile');

// other code

var descriptor1 = <htmlfileObject>.getOwnPropertyDescriptor(object1, 'property1');
Wscript.StdOut.WriteLine(descriptor1.value);

谢谢您的支持.

PS .我在这里也标记了VBScript,因为如果有人知道如何在VBScript中执行此操作,我们很可能可以轻松地将其转换为JScript.

P.S. I tag VBScript here as well because if someone knows how to do this in VBScript most probably we can easily convert it to JScript.

推荐答案

...但是,我正在使用的最新JScript版本是5.812和...

... However, the latest JScript version I'm using is 5.812 and ...

实际上,这是Windows Script Host的版本,而不是引擎JScript的版本.

Actually that is the version of Windows Script Host, not the engine JScript.

在WSH中,术语JScript默认为 ,不过是Microsoft的JavaScript引擎的别名/绰号,与标准ECMA-262第三版兼容.

In WSH, the term JScript is by default nothing but an alias / moniker for Microsoft's JavaScript engine that compatible with the standard ECMA-262 3rd edition.

除了默认引擎之外,您还可以通过指定引擎的CLSID:1b7cd997-e5ff-4932-a7a6-2a9e636da385将Chakra引擎(需要Edge)与WSH一起使用.

Besides that default engine, you can use Chakra Engine (requires Edge) with WSH by specifying the engine's CLSID: 1b7cd997-e5ff-4932-a7a6-2a9e636da385.

用于测试计算机上是否安装了引擎的命令:

Command to test if the engine is installed on the computer:

reg QUERY HKCR\CLSID\{1b7cd997-e5ff-4932-a7a6-2a9e636da385} /s

在安装了Chakra的计算机上的示例输出:

Example output on a computer Chakra installed:

HKEY_CLASSES_ROOT\CLSID\{1b7cd997-e5ff-4932-a7a6-2a9e636da385}
    (Default)    REG_SZ    JScript Language

HKEY_CLASSES_ROOT\CLSID\{1b7cd997-e5ff-4932-a7a6-2a9e636da385}\InprocServer32
    (Default)    REG_SZ    C:\Windows\System32\Chakra.dll
    ThreadingModel    REG_SZ    Both

test.js:

var object1 = {
  property1: 42
};

var descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');

WScript.StdOut.WriteLine(descriptor1.value);

使用Chakra引擎运行test.js的命令:

Command to run test.js with Chakra engine:

cscript //NoLogo //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} test.js

示例输出:

42

这篇关于使用htmlfile COM对象访问WSH JScript中对象的.getOwnPropertyDescriptor()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆