Good Way To Make Immutable Objects

Apr 8, 2006

I want to have some advice about immutable objects. I made a constructor.

function Point(x, y) {
this.x = x;
this.y = y;
}

This is a very simple one and now I want to make it immutable so that
once an object is created it cannot be modified.

I came up with 2 ways.

[1]
function Point(x, y) {
this.x = function() { return x; }
this.y = function() { return y; }
}

[2]
function Point(x, y) {
this.getX = function() { return x; }
this.getY = function() { return y; }
}

They are both immutable.
You can read x and y but cannot change them.

[1] is short and easy to use but sometimes likely to be error-prone
like
var p = new Point(2, 3);
var x = p.x; //should be p.x() instead of p.x

[2] is straight-forward but looks verbose.
I have to access the data like p.getX() .

Which way is more recommendable?
And is there a better way to make an immutable object?

View 3 Replies


ADVERTISEMENT

JQuery :: Good Web UI Component Libraries - Cross Browser Compatible And Have Good Documentation

May 10, 2009

Are there any good web UI component libraries -open source or commercial - that you can recomment? They need to be cross browser compatible and have good documentation. Jquery UI is very good but limited in number of controls it offers. YUI is very verbose and very hard to use. extJs only other one I can think of. Any others you use and like?

View 2 Replies View Related

JQuery :: Possible To Combine Two Objects To Make New One

Jul 27, 2009

Is it possible to join two jQuery objects to make a new object. For example...
var e1 = $("#firstObject");
var e2 = $("#secondObject");
var combined = e1.add(e2); // This is the expression I'm looking for
[URL]

View 4 Replies View Related

JQuery :: Make Objects Being Aware To Others (like Floating Asteroids In Space)?

Jun 4, 2011

I wonder how to create the effect of objects being aware to other objectsthis is a good example:[URL].. I'm searching for some resources and good tutorials

View 1 Replies View Related

Positioning - Moving Objects - Make The 'pivot' Point In The Centre Of The Image

Feb 22, 2009

I have some moving objects & they are using the top left spot of the object to 'hold' or 'pivot' off. how i make the 'pivot' point in the centre of the image. I think it is somewhere in this section of code:

[Code]...

View 1 Replies View Related

If And Else - Display A Message Saying Good Morning If It Is In The Morning - Good Afternoon If It Is In The Afternoon

May 31, 2011

6. Display a message saying Good Morning if it is in the morning, Good Afternoon if it is in the afternoon, and Good Evening if it is in the Evening. This is my code:

[Code]....

View 1 Replies View Related

Objects Under Mouse - Return An Array Of All Objects Underneath A Certain Point

Apr 17, 2011

Is there a way in Javascript or Jquery to return an array of all objects underneath a certain point, ie. the mouse position. Basically, I have a series of images which link to various web pages but I have a large semi transparent image positioned over the top of the other images. I want to find the href of the background image that the mouse pointer clicks over.

View 1 Replies View Related

JQuery :: Extending Objects With Internal Objects?

Sep 5, 2009

Is there a better way to extend object with internal objects?

$.fn.bestShow = function(s) {
var d = {
width: 0,
height: 0,
order: "numeric",
orderBy: "",

[Code]...

View 3 Replies View Related

How To Put Firebug To Good Use?

Nov 28, 2007

what do you use firebug for in connection with javascript?

Just want to explore new ways of using it.

Currently I use it to:

1. debug my scripts using console.log(), etc.
2. test small things in the built in 'live' console

View 2 Replies View Related

Get Good Script Books?

Apr 19, 2011

At present I am reading Javascript for Dummies, no-one tut please! Can anyone suggest a good beginners book for javascript that is easy to understand but allows progression from nothing to competent (graphics welcome); which includes everything.

View 4 Replies View Related

Good Javascript Editor

Mar 27, 2007

i want to download a free open source javascript editor :)

can anyone recommend a good one for me.. :) if you could recommend one that handles nodes and dom aspects that would be great

View 2 Replies View Related

Simple Good Old Rollover

Aug 16, 2002

I got a simple rollover with a little twist to it… and I have a little glitch.

The two only images that I am trying to get to swap are:

Button_on.jpg
Button_off.gif

That’s it. And it’s the same images for all 5 links

This means that …

all 5 links should start with button_off.gif. And any of the 5 links should swap to button_on.jpg when I get my mouse over it--while all others remain with button_off.gif.

The rollover works, but the only image that swap is on link #5. That is whether I bring my mouse to link #1 or link#2 or any other link. The only image that keeps swapping is link #5.

Check it out and try moving your pointer over the links and you’ll understand

MY TEMPLATE

Afterward, I’ll add text links above these rollovers using CSS. PS: is there a way to create a similar effect using CSS?

View 5 Replies View Related

Good Editor For Windows?

May 22, 2010

I want to know what is the best Javascript editor for Windows, that have a good syntax highlighting, IntelliSense(it's that technology of the menu when typing, like on Eclipse, but I can't remember it's correct name) and a class browser, what is very useful when you want to see the names of your classes and functions, also to browse on then.

View 1 Replies View Related

Get Good Script Tutorial?

Mar 9, 2010

I am a complete beginner to JavaScript (well I know this: document.write and alert) and I kneed a really good tutorial for beginners. Preferably free but I will pay up to �3 (not a lot I know but oh well)

View 1 Replies View Related

A Good JavaScript Reference Guide

Jul 23, 2005

I often use the HTML reference guide at Microsoft which is located
here: http://msdn.microsoft.com/library/d...ce/elements.asp

It gives a descriptions and examples of HTML elements. Can anyone
point me at any similar resources for Javascript?

View 2 Replies View Related

JQuery :: Good Pop Up Window Script?

Sep 22, 2009

Can anyone suggest to me a good jquery pop up window script.

View 3 Replies View Related

Looking For Good Lightbox / Slideshow Script

Jan 24, 2009

I was wondering are there any good slideshow scripts (transitioning image) which is also clickable into Lightbox?

View 4 Replies View Related

Good Snippet For Interactive Slider?

Jan 8, 2010

I'm looking for 5-radio button replacement. The user should be able to slide a slider between values from 0 to a 100. Text will appear under it that will say "I strongly agree" "I agree somewhat" "I am indifferent" "I disagree" "I strongly disagree" depending on the values of the slider (they should change in real-time). Unfortunately I do not have the skill to make one, especially one that has a good browser-compatibility. Does anyone know any good snippets? I'll keep searching on google and post back if I find one.

View 14 Replies View Related

Good Browser And OS Detection Code?

Jan 11, 2005

I am writing an application that (unfortunately) will work only with certain browsers and operating systems. Does anyone have a link to a good "browser/OS detection script"?

I'm looking for something simple that I can just include in each page of my html code, and us it like this:

if (! IE5.5+ for windows) {
fail
}

View 14 Replies View Related

Good Replacement For Select Element?

Jul 9, 2010

I was wondering if anybody knows of a good replacement for the select element. Maybe something using jquery?

View 7 Replies View Related

See An Editor That Comes Close Toreading A Good Book?

Jul 23, 2005

I have still yet to see a JavaScript Editor that comes close toreading a good JS book, learing it and using it with a text editor.

Anyway, here my recipe for build successfull DHTML Applications:

If you want to support only M$ IE stop here and do the following:
1) Install blindfold
2) Repeat the phrase - I love my cage :p

Buy the Book: Buy O'Reilly's JavaScript The Definitive Guide
~ The best damn JS guide & reference period, end of story, finito

Get a good Text Editor with Syntax Highlighting support
~ Real programmers don't use WYSIWYG tools
~ You will never learn with these tools
~ Code is always inefficient
~ Apps to Use:
~ OSX - BBEdit - Powerful but no MDI support :(
~ Win32 - UltraEdit - Low cost, high power, competent
yntax Highlighting
~ ^nix - Kate or KDevelop - Well written but needs KDE (big)
~ Does not work with OSX's X11 Client :[ - ('+' key
doesn't work)

Browser Development Platform
~ Mozilla (1.3+) (FireFox release suggested)
~ Why Moz?
~ Mozilla based development works in:
~ IE 95% of the time
~ Konquorer (KDE/Apple...), Opera 99%+ of the time
~ Why not IE?
~ IE based development works in standards based
browsers only 50% of the time
~ IE black hole methods (non standards based) causes
people to ignore standards based DHTML objects,
properties and methods.
~ Browser Support Baseline
~ IE 5.5sp2+
~ This is the first (reasonably) stable
version of IE for advanced JS coding.
~ When ever I experience weird bugs from users I have them
them upgrade to IE5.5sp2+ and it goes away.
~ Netscape 6.n+
~ Netscape 4.7 should not be supported!
~ Opera ? (I plead ignorance here)
~ Konquorer/Safari ? (I plead ignorance here)

Debugging Methodology:
~ Use JS Console (Moz)
~ Put try/catches at all error prone functions / methods
~ Because of IE's error stupidity, you should get as
close to the source as possible.
~ Read stack property of error in Mozilla to
read stack of error (powerful)
~ Install JavaScript Console Status in Mozilla
~ Use window.onerror handler
~ In IE, read arguments.callee.caller... to read stack
~ Goes only to last error throw point ! not error source
point :[
~ Note: at this time, there is no way to to get to
the Error object in Mozilla from this handler.
Therefore no stack in Moz. Use Try/Catch instead

Add the following code to every page:
_w=window
function getElem(s){return document.getElementById(s)}
function getEvent(e){ return is.ie?_w.event:e }

Event Declaration
~ Avoid using inline javascript declarations (In HTML Tags)
~ Inline declarations is where you call a function or
run code from the html elements definition
(onclick="<RunSomeCode>")
~ This technique will not allow you to access
the event argument in Mozilla...
~ Instead use getElem("<Element ID>").onclick=<function name>
~ Declare handlers like:
function mySlickFunction(e){e=getEvent(e)...
~ This will ensure you always have Event Object
~ If you want to get fancy you could normalize the Event
at getEvent()
~ Method Declaration
~ Declare <obj>.<meth>=function <obj_acro>_<event>(args){
~ Example: myObj.smile=function MO_smile(args){...
~ Why? - When you build you're stack in the debug
you get the method names!

Other Stuff:
~ Use JSON (www.json.org) as much as possible to nest data
structures (for more complex programming).
~ JSON is fast (primitively supported), stable easy to read.

Could anybody else add to this list?

If people are interested, I can make a document and add other stuff
like JS debugging libraries, Consoles and other slick JS Debugging
stuff.

View 3 Replies View Related

Any Good Examples Of Usage Of Document.elementfrompoint ?

Jul 23, 2005

What is meant by "element"?

When mouse is moved over "element" at x,y, is that "element" the entire
image or something else?

My thought would be to simply retrieve the thumbnail name or other ID and
use that to identify which large image to show.

Any reasons why NOT to use this property?

View 2 Replies View Related

Good Books Or Information About DHTML Menu?

Jul 23, 2005

Could someone advises me some good books or information about DHTML menu?

View 1 Replies View Related

Window.event Good For IE But Not Netscape/Firefox

May 8, 2006

I am try to detect the mouse pointer by

var event = window.event;


var x = event.pageX;
var y = event.pageY;

This is working fine in IE, but in
Netscape/Firefox where event return undefined.

Can someone tel me how to detect mouse pointer
in Netscape/Firefox?

View 6 Replies View Related

Get Good Free Drop-down Menus That Works Down To IE6?

Feb 8, 2010

I'm looking for a good JavaScript based horizontal/drop down menu that's free and works down to IE6. The Yahoo! YUI menus would probably do the trick, but seem like a bitch to understand & customize.

Any easier & more accessible options? That are rock-solid professional grade?

View 1 Replies View Related

Good Webscript Slideshow On A Loop That I Can Use In A Website?

Aug 5, 2009

Does anyone know of a good webscript slideshow on a loop that I can use in a website ? code...

Change the image every few seconds.

Slip into any element of the webpage.

All images will be the same size. Some landscape, some portrait.

Looking for this to work all in client’s scripting. or maybe AJAX

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved