question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question : Is there an option to add property value while adding property to class declaration

See original GitHub issue

Am using the below api to add a property to class

classDeclaration.addProperty({
					isStatic: false,
					name: propertyName,
					type: propertyType
				})

Am not able to specify value for the property. It will be nice if there is an option to provide value. I want to achieve the below usecase

Class A {
   test = 'myTestString'
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Aug 14, 2018

Thanks @lazarljubenovic for answering this!

@SanthoshHari912 alternatively use propDeclaration.setInitializer("newName").

1reaction
SanthoshHari912commented, Aug 14, 2018

Thanks a lot 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add property to a class dynamically? - python
Only way to dynamically attach a property is to create a new class and its instance with your new property.
Read more >
Python's property(): Add Managed Attributes to Your Classes
In this step-by-step tutorial, you'll learn how to create managed attributes, also known as properties, using Python's property() in your custom classes.
Read more >
Object.defineProperty() - JavaScript - MDN Web Docs
If an accessor property is inherited, its get and set methods will be called when the property is accessed and modified on descendant...
Read more >
Properties - C# Programming Guide - Microsoft Learn
Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code.
Read more >
Initialize Property Values - MATLAB & Simulink - MathWorks
To initialize a property value with a new instance of a handle object each time you instantiate your class, assign the property value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found