2

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.

2
  • What are you ultimately trying to accomplish? Is this HW? I would just do className.settings.remove = false and className.settings.edit = false in edit.html (or a script included therein). Commented May 14, 2009 at 4:02
  • no, this is not HW, i am doing a project, trying to use AJAX, but new to javascript Commented May 14, 2009 at 4:04

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

2

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});

Comments