Posts

Showing posts with the label OOP

Namespace your JavaScript function and variable with jQuery

We all know that global variable are evil. Namespacing  your variables and methods is now considered a good practice and shows your awareness about the trends. Anyway, I thought how can I namespace my variables and methods in jQuery. Well, first off, I can easily extend jQuery with custom written plugins. $.fn.extend({ myNamespaced: function(myArg){ return 'namespaced.' + myArg; } });

Namespace your JavaScript function and variable with jQuery

We all know that global variable are evil. Namespacing  your variables and methods is now considered a good practice and shows your awareness about the trends. Anyway, I thought how can I namespace my variables and methods in jQuery. Well, first off, I can easily extend jQuery with custom written plugins. $.fn.extend({ myNamespaced: function(myArg){ return 'namespaced.' + myArg; } });

Object-Oriented JavaScript, how to achieve public properties/fields

Recently I posted my findings about private fields in JavaScript. So this is a continuation of the post and it talks about public fields in your JavaScript code. So here is a quick example of public properties in your code: function User() { // Private property var name = ''; return { // Public property classVersion: '1.3', prevVersions: ['1.2.3', '1.2', '1'], setName:

Object-Oriented JavaScript, how to achieve public properties/fields

Recently I posted my findings about private fields in JavaScript. So this is a continuation of the post and it talks about public fields in your JavaScript code. So here is a quick example of public properties in your code: function User() { // Private property var name = ''; return { // Public property classVersion: '1.3', prevVersions: ['1.2.3', '1.2', '1'], setName:

Object-Oriented JavaScript, how to achieve private properties/fields

The very basic of Object-Oriented Programming (OOP) is private fields and public methods (not considering features like polymorphism, inheritance, etc). So how to achieve this very basic of OOP in JavaScript. It turns out to be easy. Here is how to have private fields in your custom JavaScript functions/classes and using methods of your function/class to amend it. function User() { var name =

Object-Oriented JavaScript, how to achieve private properties/fields

The very basic of Object-Oriented Programming (OOP) is private fields and public methods (not considering features like polymorphism, inheritance, etc). So how to achieve this very basic of OOP in JavaScript. It turns out to be easy. Here is how to have private fields in your custom JavaScript functions/classes and using methods of your function/class to amend it. function User() { var name =