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.
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.
Share Improve this question edited May 14, 2009 at 4:27 asked May 14, 2009 at 3:58 js_noobiejs_noobie 2- What are you ultimately trying to acplish? Is this HW? I would just do className.settings.remove = false and className.settings.edit = false in edit.html (or a script included therein). – Matthew Flaschen 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 – js_noobie Commented May 14, 2009 at 4:04
3 Answers
Reset to default 3This 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 mon in JavaScript. There is no class or constructor, you're simply assigning properties to an object using literals, thus the name object literal notation.
className.settings = {move: false, remove: false, edit: false};
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});