Open slow-typer opened 5 years ago
Actually there is no support for private member or method. I tried to stay very close to the JavaScript native language when I started to develop System Designer, this is why I did not add this feature. But you are right, private member will come soon in JavaScript, moreover when can simulate private member in JavaScript (with closure).
In fact we can add this feature, I just need to think a bit about that. But basically;
"visibility":"private"
in the JSON of the model to set a property or a method as private,-
in UML class diagram, I will check soon on how to implement that feature.
And thanks for your support!
See Douglas Crockford's excellent information on JavaScript at https://crockford.com/javascript/
The page that is relevant to this issue is at https://crockford.com/javascript/private.html
Thanks for the links.
In fact, in System Designer systems are generated in a specific way: all the models and methods are generated in memory (no code is generated), each method is executed in their own context (in the JavaScript VM), so they can not have access to the parent context.
So I had to find another way (maybe with injections).
So you're saying that the object methods are not part of the object definition? That doesn't make sense. At any rate Function.prototype.bind
can bind any method to any context, so you can set this
to be anything you want for the call.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind
When you want to create private methods / properties in JavaScript, the standard way is to do closure or define all your methods / properties in the constructor.
In System Designer, because we serialize / deserialize methods, we use new Function
so we can not have an access to the parent scope. We pass to these methods the instance context, which does not have private information.
A possible solution to have access to private methods / properties in these methods would be to pass an extended context (i.e. instance object with private methods / properties), but that context does not have to interfere with the current instance.
Another solution would be to wait for native implementation of private field in all browsers, and then use it.
I'm pretty sure you are missing some pretty fundamental concepts about how JavaScript actually works. I've got to just step away from this conversation and leave you to continue your journey. Have fun, and I wish you luck!
Thank you for this program!
Here is my environment:
How do I represent a private member in the class diagram using System-Designer? Is there support for private member variable declarations?
Recent searches for javascript private members show results that state to use "#" as a prefix for a name in javascript. But I don't know how to do this with JSON schema or JSON.
I can add a property to the Model such as the following:
"myParameter": { "description": "", "type": "string", "readOnly": false, "mandatory": false, "private": true, "default": "" }
But, on the UML class diagram, it still shows "myParameter" with a "+" prefix. Is there an entry (or way) to make it show with a "-" prefix in the UML class diagram?
Any help would be greatly appreciated.
Thanks!