getter setter syntax with non-inline functions

View: New views
2 Messages — Rating Filter:   Alert me  

getter setter syntax with non-inline functions

by bijumaillist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

// old getter setter syntax

var obj = ({
  a getter:function () {return 101;},
  a setter:function (value) {this.aaa = value;}
  });
obj.toSource();

// can be written in off-line/non-inline functions as

function aGetter() {return 101;}
function aSetter(value) {this.aaa = value;}

var obj = ({
  a getter:aGetter,
  a setter:aSetter
  });
obj.toSource();


// now when we write with new syntax

var obj = ({get a () {return 101;}, set a (value) {this.aaa =
value;}});
obj.toSource();


// I would like to know how can we write in new syntax with non-inline
functions
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine

Re: getter setter syntax with non-inline functions

by arghman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jun 15, 11:25 am, biju <bijumaill...@...> wrote:
> // now when we write with new syntax
>
> var obj = ({get a () {return 101;}, set a (value) {this.aaa =
> value;}});
> obj.toSource();
>
> // I would like to know how can we write in new syntax with non-inline
> functions

see http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Creating_New_Objects:Defining_Getters_and_Setters

particularly __defineGetter__ and __defineSetter__

_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine
LightInTheBox - Buy quality products at wholesale price