goupviet / joose-js

Automatically exported from code.google.com/p/joose-js
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

There is posibility to change "ro" values. #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the problem. 
-------------------------------
1. Please try this code: 
            Class("Point", {
                has: {
                    x: {is: "ro"},
                    y: {is: "rw"},
                },
                methods: {
                    clear: function () {
                        this.x = 0; 
                        this.setY(0);
                    }
                }
            });

         var x = new Point(); 

2. Then using Firebug console: 

>>> x
a Point meta=a Joose.Class
>>> x.setX(39)
TypeError: x.setX is not a functionjoose_test1.html (line 34) //correct
>>> x.x = 5
5
>>> x.x
5
>>> x.getX
getter()
>>> x.getX() 
5

Expected behaviour:  
----------------
x.x = 5 - this operation shouldn't be allowed 

Current behaviour:
------------------
x.x = 5 assignment is possible. 

What version of the product are you using? On what operating system?
Windows XP, FF 3.0.6, Firebug 1.2.0b3

Additional information:
-----------------------

As you can see, operation of assignment x property is allowed, but probably
for "ro" value it shouldn't. Even in dynamic javascript there should be a
way to prevent creating new properties. 
I've tried that (it's slightly different syntax, but shows an idea): 

Field.prototype = {
    _x: {ro: true},   
    get x(){
        return this._x * 3;
    },
    set x(val){
        if(this._x.ro == true)
            throw new Error("Read only property");
        this._x = val * 3;
    }
};

var field = new Field();
field.x = 3; //boom - this guy will throw exception -> red only property

Here is additional info: 

http://msdn.microsoft.com/en-us/library/dd229916(VS.85).aspx
http://ejohn.org/blog/javascript-getters-and-setters/

Thanks 

Original issue reported on code.google.com by slawomir...@gmail.com on 6 Feb 2009 at 5:50

GoogleCodeExporter commented 9 years ago
Hello Slawomir,

As far as I know, there is no way of implementing this feature in IE6,7, so 
think
this issue will become actual when the market share of those browsers 
(summarized)
will decrease to 5-10%%

Regards, Nickolay

Original comment by nickol...@gmail.com on 6 Feb 2009 at 6:14

GoogleCodeExporter commented 9 years ago
Hey,

we could indeed enforce the read-onlyness in supporting browsers. Right now, 
"ro"
only means that no setter (setVariableName) will be generated, so if you 
attempt to
set the var using a setter you will get an error. There is, however, never 
protection
against direct access to a variable.

Original comment by malte.ubl on 6 Feb 2009 at 6:47