Re: [Proto-Scripty] как создавать в классе правильно частные и публичные методы и свойства
I read and understand a lot of russian but I'd rather not try to write it. Hope answer in english will be of any help to you. To have private functions and properties you need to use clousure like this: var AClass = Class.create((function() { var _stat = 'I am static private'; function initialize() { this.test = 'I am private'; } function _priv() { console.log(this.test); } function _private() { console.log(_stat); } return { initialize: initialize, pub: function() { _priv.apply(this); }, publi: function() { _private(); }, setpubli: function() { _stat = 'after set'; } }; })()); document.observe(dom:loaded, function() { var a = new AClass(); a.pub(); a.publi(); a.setpubli(); var b = new AClass(); b.publi(); }); Inheritance: var ASubClass = Class.create(AClass, (function() { function initialize($super) { $super($A(arguments)); } return { initialize: initialize, pfun: function() { console.log('in sub '); } }; })()); There is much more to explore on this subject. Have fun Вот например класс var myClass=Class.create ( initialize :function(){} , action:function () {} ) Метод action публичный(я так понимаю)...а как создать приватный метод -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/s5jE0forsHgJ. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] как создавать в классе правильно частные и публичные методы и свойства
Sorry, one not so small mistake: should be function initialize() { this.test = 'I am public'; } this is public of course I read and understand a lot of russian but I'd rather not try to write it. Hope answer in english will be of any help to you. To have private functions and properties you need to use clousure like this: var AClass = Class.create((function() { var _stat = 'I am static private'; function initialize() { this.test = 'I am private'; } function _priv() { console.log(this.test); } function _private() { console.log(_stat); } return { initialize: initialize, pub: function() { _priv.apply(this); }, publi: function() { _private(); }, setpubli: function() { _stat = 'after set'; } }; })()); document.observe(dom:loaded, function() { var a = new AClass(); a.pub(); a.publi(); a.setpubli(); var b = new AClass(); b.publi(); }); Inheritance: var ASubClass = Class.create(AClass, (function() { function initialize($super) { $super($A(arguments)); } return { initialize: initialize, pfun: function() { console.log('in sub '); } }; })()); There is much more to explore on this subject. Have fun Вот например класс var myClass=Class.create ( initialize :function(){} , action:function () {} ) Метод action публичный(я так понимаю)...а как создать приватный метод -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/s5jE0forsHgJ. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] как создавать в классе правильно частные и публичные методы и свойства
а вот так var myClass= Class.create( { initialize:function(str) { this.str=str ; this.msg=function() {alert (privat+this.str);} } , public:function() {alert (public+this.str)} } ) метод msg приватный или нет -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/A83FErmgpk4J. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] как создавать в классе правильно частные и публичные методы и свойства
No, this method `msg` is public. But if you create var myClass= Class.create( { initialize:function(str) { this.str=str ; msg=function() {alert (privat+this.str);} } , public:function() {alert (public+this.str)} } ) then `msg` is private. All method that your add to `this` will be public. For creating private methods use that was advised or agreements (for example: all private methods started with __ - __private_method, public_method). -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] как создавать в классе правильно частные и публичные методы и свойства
понедельник, 7 января 2013 г., 20:59:28 UTC+2 пользователь mikhail написал: No, this method `msg` is public. But if you create var myClass= Class.create( { initialize:function(str) { this.str=str ; msg=function() {alert (privat+this.str);} } , public:function() {alert (public+this.str)} } ) then `msg` is private. All method that your add to `this` will be public. For creating private methods use that was advised or agreements (for example: all private methods started with __ - __private_method, public_method). но в таком случае msg получается глобальной...это не совсем хорошо..правда?? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/-n1ZbMSiAi8J. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.