- From: Scott Miles <sjmiles@google.com>
- Date: Sun, 23 Jun 2013 12:45:48 -0700
- To: Bronislav Klučka <Bronislav.Klucka@bauglir.com>
- Cc: public-webapps <public-webapps@w3.org>
- Message-ID: <CAHbmOLa55Y0NaE66Lp94mUnJf3ax6hY28exLOveEr5=ux85Y8w@mail.gmail.com>
You can use `polymer-dev@googlegroups.com` for polymer questions. But the answer is the same. For less confusion, make the prototype first, however you want, *then* register it. if (this !== window) { var prototype = { "readyCallback": function() {} }; Object.defineProperties(prototype, { "foox": { "value": function() { alert('d'); }, } }); this.register(prototype); } On Sun, Jun 23, 2013 at 12:38 PM, Bronislav Klučka < Bronislav.Klucka@bauglir.com> wrote: > Hi, > > I actually came across this issue while using Polymer's platform.js... > I could not make it work... > > I have to do magic like this... > <element name="x-bauglir-listitem" constructor="XBauglirListItem"> > <script> > if (this !== window) > { > var first = true; > this.register({ > prototype: { > "readyCallback": function() { > > > if (first) > { > Object.defineProperties(XBauglirListItem.prototype, { > "foox": { > "value": function() { > alert('d'); > }, > } > }); > } > first = false; > }, > > } > }); > } > </script> > </element> > putting the definition outside readyCallback caused unknown XBauglirListItem > error > > so I'm wondering how it's gonna be in web Components... since the > mechanism is the same... until readyCallback i called, the construstor > function does not exists I assume > > ------------------- > ({ > readyCallback: function() { }, > get foo() {}, > set foo() {} > }) > confuses me... I 've seen the whole > ({ > }) > contruct in web comps for the first time and I think it's web comps > specific... > > and the setters and getters... from your example... are those getter and > setters for method foo or property foo? Shouldn't setter have a parameter? > The value that is about to be set? how do I define whether property is > changable, enumerable? > > Or is this working proposition of Web Comps based on working proposition > of ES6? > > Brona > > > On 23.6.2013 21:11, Scott Miles wrote: > > To be clear, this question doesn't really have anything to do with the > components spec. The bottom line from the spec is that the completion-value > of the script should reference an object that will be used as the element > prototype. > > How you generate that prototype is completely up to you, and there are > many ways you can do it. See examples below. > > Fwiw, my team (http://www.polymer-project.org/) is not an advocate of > the completion-value gambit. We are pushing for two-way initialization. In > other words, a separate method to register the prototype. > > In any case, here are examples. > > You can use descriptors, but you don't need them for get/set: > > ({ > readyCallback: function() { }, > get foo() {}, > set foo() {} > }) > > if you really want to use descriptors, you can do > > Object.create(Object.prototype, { > property: { > get: function() { return 5; }, > set: function(value) {} > } > }); > > or you can mix and match: > > var prototype = { > readyCallback: function() { }, > }; > Object.defineProperty(prototype, { > property: { > get: function() { return 5; }, > set: function(value) {} > } > }); > prototype; > > > On Sun, Jun 23, 2013 at 11:45 AM, Bronislav Klučka < > Bronislav.Klucka@bauglir.com> wrote: > >> >> On 23.6.2013 20:42, Bronislav Klučka wrote: >> >>> Hi, >>> >>> http://www.w3.org/TR/2013/WD-components-intro-20130606/#lifecycle-callbacks >>> shows defining element methods, next to the life cycle it also shows >>> definition of methods "ticks" and "chime", >>> I wonder how this construct >>> >>> ({ >>> >>> }); >>> >>> is compatible with ES5 object properties descriptors, in ES5 it is >>> possible to define getters and settes for properties/methods, is it the >>> possible to do something like >>> >>> <element .....> >>> ... >>> <script> >>> >>> ({ >>> readyCallback: function () { >>> //init component >>> }, >>> }); >>> >>> Object.defineProperties(this.prototype, { // or maybe >>> Object.defineProperties(this, { >>> "property": { >>> "get": function() { return 5; } >>> "set": function(value) {} >>> } >>> }); >>> </script> >>> >>> </element> >>> >>> Will it work? Is it suppose to work? >>> >>> Brona >>> >>> >>> >> Of course I ment >> Object.defineProperties(ElementConsructorName.prototype >> >> Brona >> >> > > -- > > s pozdravem > Bronislav Klučka > > > > [image: http://www.bauglir.com] <http://www.bauglir.com> > > http://www.bauglir.comBronislav.Klucka@bauglir.com > > * webové aplikace > * software na zakázku > > >
Attachments
- image/gif attachment: bauglir_small.gif
Received on Sunday, 23 June 2013 19:46:15 UTC