简体   繁体   中英

How to set expando property of JScript with proper Javascript/ECMA?

I'm writing XP-VAPI scripts in HP ALM and some objects of the OTA-API use a construct which looks like this:

object.Field('nameOfField') = newValue;

Obviously this is not valid in Javascript. But because I use an IDE that checks the syntax according to ECMA standards this is shown as a syntax error. So I wonder is there a way to do this assignment with a proper Javascript syntax? I tried the following variants with no success:

CurrentRun.Field("RN_USER_13").value = 'pfusch';
CurrentRun.Field.RN_USER_13 = 'pfusch';
CurrentRun.Field["RN_USER_13"] = 'pfusch';
CurrentRun["RN_USER_13"] = 'pfusch';
CurrentRun.RN_USER_13 = 'pfusch';

Try this:

Object.defineProperty(CurrentRun,'RN_USER_13',{
  enumerable: true,
  configurable: true,
  writable: true,
  value: 'pfusch'
})

Here is a reference for Object.defineProperty and here is a great SO post about that topic: how to use javascript Object.defineProperty

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM