views:

603

answers:

3

PROBLEM SOLVED.

Special thanks to Andrew Noyes for explaining its not a class but a Object Literal Notation. What a noob am I..

EDIT:

SORRY, i made a mistake in my js file, the structure of my js is like this:

(I am totally new to javascript, i need your guys help here...)

var className = {

settings : {
    setA  : true,
    setB: true,
    setC: true,
    },

    Default : {
        move: true,
        remove: true,
        edit: true,\
    },
    ...
}

And in my html, index.html, i include the class.js file, but i want to change the setting to like:

    Default : {
    move  : false,
    remove: false,
    edit: false,
    }

because only the edit.html, users are allowed to move, remove and edit.

How do I do that? Should I have 2 js, class_disable.js (include in index.html) and class_enable.js(for edit.html)?

Need your advise..

I tried:

 className.settings.Default = {move = false, remove = false, edit = false};

But it does not work.

+1  A: 
className.settings = {move: false, remove: false, edit: false};
Chris Jester-Young
+1  A: 

or long way:

className.settings.move = false;
className.settings.remove = false;
className.settings.edit = false;

Another way would be if you use jQuery:

$.extend(className.settings, {move: false, remove: false, edit: false});
Dmitri Farkov
+2  A: 

This isn't valid syntax:

className.settings.Default = {move = false, remove = false, edit = false};

Object values are assigned using a colon, as follows:

className.settings.Default = {
    move: false,
    remove: false,
    edit: false
};

Alternatively, you could use this syntax:

className.settings.Default.move = false;
className.settings.Default.remove = false;
className.settings.Default.edit: false;

What you're using here is not a class, it's called Object Literal Notation, and is very common in JavaScript. There is no class or constructor, you're simply assigning properties to an object using literals, thus the name object literal notation.

Andrew Noyes