Object Literal

Oct 17, 2006

Below I declared a basic object literal with 2 methods. The
"doSomething" method is call from the "useDoSomething" method but the
call is only sucessful if I use the "this" keyword or qualify the call
with "SomeObj".

Can someone describe why this is happening?

var SomeObj = {
doSomething : function()
{
return 'Did something'
},

useDoSomething : function()
{
//Doesn't work - doSomething() no defined.
return doSomething();
//Works
//return this.doSomething();
//Works
//return SomeObj.doSomething();
}
}

alert(SomeObj.doSomething());
alert(SomeObj.useDoSomething());

View 11 Replies


ADVERTISEMENT

Literal Notation: Change Values Of A New Object Without Changing The Parent-object?

Oct 9, 2010

I have the following code:

A = {
"value": "a",
};
B = A ;
B.value = "b";
alert (A.value); // => b

I expected A.value to be "a". how can I change values of a new object, without changing the parent-object?

View 6 Replies View Related

Difference Between The Object Literal And The New

Jul 2, 2010

I have read this from the interentfunction getArea(radius)

Imagine we want to create lots of circle objects using our object as a base - if we declare using the object literal, were not able to do that.

But the new operator can do that - basically allowing us to re-use a user-defined object.

can't understand on the above why we declare using the object literal not able to do that.

View 8 Replies View Related

Object Literal - Getting The Functions To Run

Oct 2, 2007

I am having a hard time getting the javascript file to run any of the functions after I've changed my original script to object literal format. Please tell me why it isn't working! I have attached a zip format of my code.

View 4 Replies View Related

IE - Object Literal Notation Error

Jul 1, 2009

I'm declaring a class in OLN:

Code:

The problem is that in IE, when I call myfunc() it complains with the error: Class is undefined

I'm not sure what I'm doing wrong. Class is declared in as much global scope as possible, and that shouldn't even matter in JS.

View 3 Replies View Related

Calling A Method In Object Literal ?

Sep 22, 2009

I have this below code snippet

I have an object myscript and from within the method validate, i want to call the method init. so is there there anyway that I can call the method init without having to prefix like this: myscript.init();

I tried this.init(); but it's not working

Code:

View 15 Replies View Related

Private Methods In Object Literal?

Aug 18, 2010

i have something like this:

Code:
var o = {
f1:function(a) {

[code]....

View 4 Replies View Related

Make Copy Of Object Literal?

Mar 30, 2011

Consider the following:

Code:
myObjLit = {
prop1:null,

[code]....

View 2 Replies View Related

Literal Inherit From A Literal?

Nov 22, 2010

what is the best way to setup one literal to be the prototype for another?So far I can only think of making a copy into a constructor.

Code JavaScript:

var meths = {
// creates a constructor function populated with a shallow copy of child
// the prototype for the new instance is set to the parent.

[code]....

View 8 Replies View Related

Replace String Literal

Jun 6, 2006

How would one make the ECMA-262 String.replace method work with a
string literal?

For example, if my string was "HELLO[WORLD]" how would I make it work
in this instance.

Please note my square brackets are not regular expression syntax.

View 21 Replies View Related

Parameterizing A String Literal

Mar 16, 2007

A section of my webpage consists of two dozen lines of text displayed
by sequentially calling:

function printText1( text )
{
document.getElementById( "textLine1" ).innerHTML = text;
}
....
function printText24( text )
{
document.getElementById( "textLine24" ).innerHTML = text;
}

Is there a way to parameterize the string literal (textLineXX) so that
I can do it all by repeatedly calling one printText function?

View 7 Replies View Related

Use A Literal In A Function Declaration?

Jun 14, 2010

I have the following code which attaches a function to events in x number of comboboxes (x will probably always = 4, but I do not want to hard-code this). I wish to pass the value of i to the function being attached as well as the value of tempData. In other words, I want the parameters in function to be the value, not a reference variable.

In the current example, I am using the hard-coded variable ci. This I want to be replaced by a literal created when the event handler is attached (the value of the loop variable i). Also, notice that I get the filter value in the event handler (assigned to the variable ct). I would like to replace this code with the value of tempData which would also be determined when the evenet is attached (it is the same value in this case, but it keeps the onChange event from having to do this each time it runs).

var props = {
col_0: "select",
col_1: "select",

[code]....

View 6 Replies View Related

Unterminated String Literal

Jan 25, 2006

im trying to read an xml file and put it into a textarea on my page.
here is the code that returns the xml file as a string:

Document doc = new Document();
SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
doc = saxBuilder.build(filesName);
String xml = outputter.outputString(doc);

no when i try to pass this to a javascript as follows:
function putXML(fileName){
var blah = '<%= xml %>'
document.btraxtestForm.HighwayMessage.innerText=blah;
}

it gives me a unterminated string literal error.

also, i will never know the contents of this xml file so i cant split up the string.
has anyone any ideas how i will fix this?

View 5 Replies View Related

Objects With Literal Notation ?

Aug 17, 2010

I've started learning writing javascript objects with literal notation...

Instead of the usual syntax...

The problem is that it's hard for me to adapt procedures which I'm used to within the normal syntax for the literal notation. E.g:

Is this variable global or local? If it's local, how do I declare a variable globally? I also wonder if it is possible to bind events to objects from within the object? And if I'm correct - jQuery is coded this way, but how can they then make use of their selector:

When it is an object defined with literal notation that doesn't have a constructor?

View 2 Replies View Related

Get A Dynamic Value Into A Literal Array?

Jan 2, 2011

There are two arrays named myContacts and getRes. When I use myContacts array it works fine. When I assign some value for getRes array which is exactly similar format like mycontacts array, but it’s a dynamic value which I already checked no error In the data content. But am facing problem with dynamic value which gave me not same as myContact. tq

var myContacts = "";
var getRes = "";

[code]....

View 2 Replies View Related

Looping Variables In A Function Literal

Oct 19, 2005

Below is a stripped down example of code I'm using to count links in a
list. My intent with the ShowLinkNumber() function was to display the
number of the current link. (e.g. click on link 2, and the message "2"
pops up; click on link 4, and you see a "4.")

For reasons I can't trace, my function always displays the last number
in the list. Why does it do this, and can anyone suggest a way to
achieve my goal without adding markup? Code:

View 3 Replies View Related

How Do I Make & A Literal Character In An XML Parse?

Jun 23, 2006


The XML my PHP app is returning to my JavaScript function has elements in
it that contain special characters... specifically the ampersand & which
hoses up the data. ex: Company Name = "K & B Construction".

Can anyone give me some idea of how I make the data coming out of my
database translate as literal characters in the XML output?

View 5 Replies View Related

Error: Unterminated String Literal

Jan 24, 2009

Error: unterminated string literal

on this line?

document.getElementById('id_company').innerHTML = '<span class="textGreen"><strong>news</strong></span>';

View 1 Replies View Related

Unterminated String Literal From Paste?

Jun 30, 2011

I created a simple WYSIWYG for creating CSS based webpages. It works exactly as assumed in Safari and Chrome. However, in firefox, when you copy/paste more than one line of text, instead of formatting it as html, in puts in line breaks causing the array storing all of the data to break into multiple lines and causing an unterminated string literal.

1. suggest why it is behaving this way?
2. suggest a work around to allow it to work on FF?

View 2 Replies View Related

Getting Unterminated String Literal Error?

Oct 8, 2011

i am getting this error " unterminated string literal" but iam unable to locate the problem..iam using fire bug for firefox..

View 6 Replies View Related

Passing Variable To Function As A Literal?

Apr 24, 2010

I've been banging on this for a couple hours even though I'm sure it has a less-than-five-second fix. Hopefully somebody will glance at it and point out the obvious thing I'm missing.I'm using the onchange event of an html select element to trigger an array prototype function that looks for a value in an array and returns the indices of the array that contain that value, or FALSE if the array doesn't contain the value. For this example, here's the array being set up:

var instids = new Array();
instids[0] = 5;
instids[1] = 6;

[code]....

View 1 Replies View Related

Starting Literal Objects As Function?

Dec 31, 2009

How do I start my literal object as a function like you do when you use the new Object method.

e.g. var fn = function(){ ...code...}
var func = new fn();

I'm trying to achieve this using the literal object method like:

var fn ={
key: ''
}

View 2 Replies View Related

JQuery :: Passing Function Literal Via Event?

Apr 1, 2011

Am I able to pass a function literal (at least I think that's what it's called) to a jquery event handler, and retrieved the event details in the function?

[Code]...

View 2 Replies View Related

Strange Unterminated String Literal Error

Dec 22, 2007

I can't find anything wrong with this code <!-- Initialise the editor --><script>
initRTE('<table align="" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr></tr></tbody></table>', 'example.css');
</script>

However this throws an error in firebug and the page doesn't display it correctly, i get an error in firebug

unterminated string literal
initRTE('<table align="" border="0" cellpadding="0" cellspacing="0" widt...
Does anyone have and idea whats going on?

View 16 Replies View Related

Creating An Array Literal Using A Large Recordset From A Database

Feb 9, 2006

The correct syntax for an array literal would be:

this.managers [ "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W" ];

(which works)

My questioin is, how do you recreate this same syntax pulling from a
recordset containing over 3500 records such as:

aManagerName = "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W", etc...

because

this.managers [ aManagerName ];

(does not work)

View 6 Replies View Related

SetTimeout() Syntax Convert Expression To Literal String?

Apr 16, 2011

<p> Howdy <p> expressed as a literal string that is passed to the setTimeout() function might look like this: setTimeout("document.getElementById('first').innerHTML = '<p>' + 'HOWDY' + '</p>';", 2000);

I guess you can't just put quotes around an expression like this: "'<p> HOWDY </p>;" So tags have to be isolated, but it get confusing with expressions like this, which I am not sure how to express as a string:

<p><h2 class="pos_left"> <img src="car1.jpg" name="slide" width="400" height="250" /> </h2> </p>

I wish I could change the " in there to ' and then just wrap the whole thing in double " This is what I came up with but it did not work: setTimeout("document.getElementById('first').innerHTML = '<p>' + '<h2' + 'class='pos_left'' + '>' + '<img' + 'src='car1.jpg'' + 'name='slide'' + 'width='400'' + 'height='250'' + '/>' + '</h2>' + '</p>';", 4000);

View 6 Replies View Related







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