[ 4 posts ]

Daniel Ji

  • Username: humblepie
  • Joined: Tue Feb 28, 2012 10:30 am
  • Posts: 147
  • GitHub: humblepie
  • Gists: humblepie
  • Offline
  • Profile
Tags:

Y.Base.create & protected properties

Post Posted: Tue Jun 12, 2012 9:41 am
+0-
Hi everyone,

I was wondering if there's a way to create 'protected' scope properties or functions using Y.Base.create().
Code:
Y.Base.create ( name  main  extensions  px  sx )
I believe the px and sx arguments create public scope properties and methods.

Thanks.

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 619
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile
Tags:

Re: Y.Base.create & protected properties

Post Posted: Wed Jun 13, 2012 7:44 am
+0-
No. Y.Base.create copies functions into the newly created constructor's prototype. So everything you use in "px" is public. There is no easy way in JavaScript to have private/protected instance data that can be accessed from prototype methods (if you're interested, last weak I posted a gist with a somewhat convoluted way of doing it: https://gist.github.com/2901426).

In YUI there is a convention to mark private/protected methods with an "_" prefix and use YUIDoc to declare if it's private or protected.

Daniel Ji

  • Username: humblepie
  • Joined: Tue Feb 28, 2012 10:30 am
  • Posts: 147
  • GitHub: humblepie
  • Gists: humblepie
  • Offline
  • Profile

Re: Y.Base.create & protected properties

Post Posted: Wed Jun 13, 2012 9:38 am
+0-
Hi Juan,

Private scope is easy enough to create using function scoping, but protected methods/properties aren't straight forward in my mind.

Oh well, if anyone has general approaches to creating protected properties/methods then please let me know :)

Thanks.

Nick Husher

YUI Contributor

  • Offline
  • Profile

Re: Y.Base.create & protected properties

Post Posted: Wed Jun 13, 2012 10:20 am
+0-
Note that there are a few places where closure-scoped variables (effectively "static private" variables) have made it very difficult to override specific YUI functionality.

It's been my experience that in JS, unless you have a really good reason to make something private, you shouldn't sweat exposing data.
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum