Making private members in javascript using Symbol

February 28th, 2015 admin

Quoting mozilla website:

A symbol is a unique and immutable data type and may be used as an identifier for object properties. The symbol object is an implicit object wrapper for the symbol primitive data type.

So. How can we use it to achieve what we couldn't do before - creating private member in javascript.

Have a look at the example below:

var Product = (function () {
	// creating our symbol which will be our key to store private members
	var symbol = Symbol('product');
	// this object will have to store the private members
	var privateMemebers = function () { = null;
		this.price = null;
	// our class constructor
	var Product = function () {
		// this is the line where we are specifying where
		// this instance of this class will store its private members
		this[symbol] = new privateMemebers();
	// prototype of our class with getters and setters operating with private mambers
	Product.prototype = {
		getName: function () {
			return this[symbol].name;
		setName: function (value) {
			this[symbol].name = value;
		getPrice: function () {
			return this[symbol].price;
		setPrice: function (value) {
			this[symbol].price = value;
	return Product;
// example
var product1 = new Product();
var product2 = new Product();
console.log('product1.getName()', product1.getName()); // should display 'product1'
console.log('product2.getName()', product2.getName()); // should display null
console.log('product1.getPrice()', product1.getPrice()); //  should display null
console.log('product2.getPrice()', product2.getPrice());  // should display 200

That is pretty much it. This is still an experimental technology, part of the Harmony (ECMAScript 6) proposal. So be careful. Even though it is supported by Google Chrome

Posted in Uncategorized | No Comments » how to make asp:button render a button tagname with type=submit

March 25th, 2011 admin

Sometimes when I try to style the asp:button I get pretty frustrated because it has its limitations as it's not a container so you can't add any elements inside it. The real question is - why did Microsoft not make it possible to change the asp:button behaviour so it would be the option which tag you want to render? [sigh]
There are some articles in the internet saying how you can fix that by using web control adaptors or even javascript.
But what I really wanted is to have a different control that would render what I wanted it to. So I came up with the solution of extending the standard asp:button and overriding a couple of methods in it. The code is below. It's very simple and seems to work for me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.WebControls;
namespace MyControls
    /// Class extending Button, but rendering button type='submit'
    public class ButtonSubmit : Button
        public ButtonSubmit()
            : base()
        { }
        public string Value
                string str = (string)ViewState["Value"];
                if (str != null)
                    return str;
                return string.Empty;
            set { ViewState["Value"] = value; }
        public override void RenderBeginTag(HtmlTextWriter writer)
        protected override void RenderContents(HtmlTextWriter writer)
            if (HasControls())
        protected override void AddAttributesToRender(HtmlTextWriter writer)
            // substitute "text" with "value" because the base class uses "text" for "value"
            string strText = Text;
            Text = Value;
            Text = strText;

Posted in, c#, development, Uncategorized | No Comments »

How to Install IE9 on Windows XP

March 17th, 2011 admin

This is just not fair. If you're a web developer and you've got Windows XP running on your machine - Microsoft actually force you to pay them in order to upgrade your system. I've come across this article telling us about the ways you can use to install Internet Explorer 9 on Windows XP. But apparently - you can't do this. So spend some money and be happy.

Posted in Uncategorized | No Comments »

Hello world!

March 13th, 2008 admin

Hi all, here I am starting writing my notes that can be related to anything - .net developing, php developing, sql-quering, or even my personal life.

Posted in Uncategorized | No Comments »