| Page 1 of 1 | [ 4 posts ] |
|
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 DopazoYUI Contributor
|
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. |
|
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. |
|
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. |
| Page 1 of 1 | [ 4 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group