Is it possible to make the setter and getter not for object properties and object itself?

Know how to set the getter and setter for object properties, like so

Osobaya_peremennaya function() {} // Class

Osobaya_peremennaya.prototype = { // Set the setter and getter
 set znachenie_peremennoy (znachenie) {
 console.log('Any other action');
 this._znachenie_peremennoy = znachenie;
},
 get znachenie_peremennoy () {
 return this._znachenie_peremennoy;
}
};

// Use
prozrachnost = new Osobaya_peremennaya;
prozrachnost.znachenie = 0.5;

console.log(prozrachnost.znachenie);


But I would like to avoid accessing a property and use the assignment that is like that
prozrachnost = new Osobaya_peremennaya;
prozrachnost = 0.5;

console.log(prozrachnost);


Why this is necessary. For example in WebGL that would give the variable which we have specified in the Shader what the data have to write about this place.
webgl_context.uniform1f(webgl_context.getUniformLocation(shader_programm, "prozrachnost"), 0.5);

// The line above looks nicer if it is in the setter
prozrachnost.znachenie = 0.5;

// Is it possible to reduce to this?
prozrachnost = 0.5;


Perhaps there is a completely different solution?
June 10th 19 at 16:20
2 answers
June 10th 19 at 16:22
Solution
Well, you can put the object in the window and make the appropriate getter and setter.
Object.defineProperty(window, 'prozrachnost', {
 set(value) {
 if (value instanceof Osobaya_peremennaya) {
 window._prozrachnost = value;
 } else {
 window._prozrachnost.znachenie = value;
}
},

 get() {
 return window._prozrachnost;
},
});

window.prozrachnost = new Osobaya_peremennaya;
window.prozrachnost = 0.5;

(I did not try. and if without a window. in strict mode will not start)

But do all this the getter-betternow magic not very fun to read, and to rake debajit. Better do as advised, he said, all right.
Very good =D
Really works and without window.
Beauty. - price.Swift commented on June 10th 19 at 16:25
what I've done:D - genevieve_Upton commented on June 10th 19 at 16:28
June 10th 19 at 16:24
Solution
No. You assign the variable another value, losing instance of an object.
If you need to cut a record, write a method in the object that will handle multiple variables of the parameter object.
As something like this:
myshader.someFunc({foo: "This", bar: "works!"})
Thank you. Thought about this for a solution, rather it is more correct, but still prefer the option - price.Swift commented on June 10th 19 at 16:27

Find more questions by tags OOPJavaScript