Storing Element References As Public Object Members

Sep 20, 2006

I've spent several days trying to work this out. Maybe I'm just
searching for the wrong keywords/phrases.

I have some code that looks like:

[-- snippet starts --]
Console = new Object();
Console.init = function() {
this.STDIN = document.getElementById('console0_stdin');
this.STDOUT = document.getElementById('console0_stdout');

// set styles on the element references, eg:
this.STDIN.style.width = ï`%'
this.STDOUT.style.width = ï`%'
}

Console.focus = function() {
this.STDIN.focus();
}

Console.writeln = function(buffer) {
this.STDOUT.value += "
" + buffer;
}

[-- snippet ends --]

I'm not sure why, but the Console.focus() and Console.writeln() methods
just don't seem to be able to use the DOM references stored in
Console.STDIN and Console.STDOUT. Everything's fine in the
constructor, but other methods can't seem to use them.

View 8 Replies


ADVERTISEMENT

Members Of The Error Class/object

Apr 18, 2006

What're the members of the error class/object? Is there a complete reference to all JavaScript objects available on the Web?

View 6 Replies View Related

Object References

Dec 17, 2005

I am a bit new to JavaScript objects, I have the following object:


LinkTest=function() {
// init
}

LinkTest.prototype.eventHandler=function(){
// the call below fails, as 'this' refers to the link that
// generated the event, and not the instance of LinkTest object
this.doSomething();
}

LinkTest.prototype.register=function(link){
link.onclick = this.eventHandler;
}

LinkTest.prototype.doSomething=function() {
// do something!
}

So basically when you register a link, the onclick event handler gets a reference to LinkTest's eventHandler function. Now when the user clicks on the link, the 'this' refers to the link... how do I reference the instance of LinkTest object from within the eventHandler function?

View 2 Replies View Related

Passing And Using Variables In Object References

Mar 9, 2003

I am trying to make a function that checks/unchecks a checkbox when a specific <td> is clicked. I need to use this same function for several checkboxes in the page so I want to just pass it the name of the checkbox I want to affect as a variable and use it in the object reference lines. BUT, this doesn't work. I can pass the variable to the function as I've used alert(variable) to test this. But it doesn't work when I put it in a line like this "document.forms[0].variable.checked=true;". Code:

View 4 Replies View Related

Object Members That Are Prototyped As Arrays Become Shared By All Class Instances?

Dec 12, 2010

Has anyone noticed this behavior before? This really threw me off... I would have expected prototyped arrays to be private to each class instance rather than shared between all class instances.

HTML Code:
<html>
<head>
<script type="text/javascript">

[Code]....

View 3 Replies View Related

Object References When Using Bound Event Handlers

Feb 27, 2007

THE QUESTION: How do I get a reference to my Object when processing an
event handler bound to an html element ?

CONTEXT:
Sorry if it is a bit long.

I am developing a JS calendar tool. One of the requirements is that the
calendar will need to display a varying number of months (1..3)
depending on the calling page. Imagine 1, 2 or 3 calendar pages side by
side as required.

I have built a grid object that will contain one month's dates with the
day names at the top. The calendar object inherits the grid object as an
array of "calendar pages" - one grid per month and the calendar provides
the content for each grid. I will use the grid object for another
completely different object later and so I want to use good OOP
encapsulation. The grid is a table generated on the fly and is "dumb" as
far as what it is used for.

I have attached an onlick event to each cell of the grid. Using OOP
priciples I want the calling program (the calendar object in this case)
to provide a function to handle the click and the grid object will
provide to the calendar the row and column of that cell as well as the
grid number (so the calendar can work out which date was clicked since
it knows what the data means and the grid doesnt). Code:

View 6 Replies View Related

Closures / Object References And Private Methods

Aug 22, 2010

I have some confusion about the scripts below:

1) is getRule a local variable or global variable, as it has no var keyword, yet it is an inner function of Validation? So without var, I think global, but being an inner function, I think local. So I'm not sure which.

2) In this line of code: var rule = $.Validation.getRule(types[type]), getRule returns rules, which is just a local variable in Validation. I always see that you return functions, but how does returning a local variable that's just an object literal and not a function be able to return true or false? Now the value of rules is an object literal, and this object returns true or false. So we are basically allowed to use return keyword with local variables that are object literals and not functions?

3) In this line, is foo(age) being called, or is it just being assigned to bar OR is it being called and THEN assigned to bar: var bar = foo(age);

4) Now for the most confusing: age is obviously an object reference as opposed to a literal in the example. Does that make a difference in regards to closures?
Note that I read a number of books, including JavaScript Programmer Reference and Object Oriented JavaScript and jQuery cookbook, which compare primitives vs reference types and how primitive types store directly in memory whereas reference tpyes reference memory, so if one reference changes, they all change where primitive remains ingrained. But when assigning a function as a reference like this, how does that affect the object "age" when passed into bar?

Code:
(function($) {
/*Validation Singleton*/
var Validation = function() {
var rules = {
email : {
check: function(value) {
if(value)
return testPattern(value,".+@.+..+");
return true;
}, .....
$.Validation = new Validation();
})(jQuery);

Code:
function foo(x) {
var tmp = 3;
return function (y) {
alert(x + y + tmp);
x.memb = x.memb ? x.memb + 1 : 1;
alert(x.memb);
}}
var age = new Number(2);
var bar = foo(age); // bar is now a closure referencing age.
bar(10);

View 3 Replies View Related

Protected Static Members, Abstract Classes, Object Composition Vs. Subclassing

Nov 26, 2005

I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you experts.

I would like to produce Javascript classes that can be "subclassed"
with certain behaviors defined at subclass time. There are plenty of
ways to do this through prototyping and other techniques, but these
behaviors need to be static and protected. By protected this means
that they can be overridden (or reassigned) in subclasses, and
privileged subclass methods can access them, but callers external to
the class cannot.

I've been attempting to define a factory function that transfers its
parameters to an anonymous object while defining the constructor in a
-with- block. (This is what I'm loosely referring to as "subclassing"
- it's really object composition.) This works, but not for
externally-defined functions. They can't see the protected static
members....

View 11 Replies View Related

Shorten Form Element References?

Dec 5, 2010

is there a way to shorten something like:document.scoresheet["HomeTotalHCaps"].valueto a simple short name like var1.value ?

View 8 Replies View Related

Test Object Equality Using Data Inside - Not References - Possible?

Jan 29, 2009

Is it possible to test whether two objects are equal using the data they contain inside and not comparing their pointers with ==?

Well actually of course there is but...

Is there a way to do it without actually looping through the object, instead maybe something that came with JS? (something like a .equals() method from other programming languages.)

View 5 Replies View Related

JSP: Storing Object To PageContext: Old Fashioned?

Dec 14, 2006

JSPs seem to offer more than one way of storing Objects to a session context for session tracking purposes.

Both these seem to work Ok in my JSP code on Tomcat 5.0.x:

// using pageContext with session scope
pageContext.setAttribute("name", myObject, PageContext.SESSION_SCOPE);

// using the session context of HttpServlet
session.setAttribute("name",myObject);

Whats the difference here? Is there a preferred way to do this?

View 1 Replies View Related

Storing Element In Array?

Apr 9, 2009

I could use some help with a form I am trying to complete. If someone could PM me and I could attach the file. It's only a small problem but I am tired of spending hours trying to figure it out.

View 1 Replies View Related

Storing An Element's Colour As A Variable?

Jun 4, 2009

I tried and tried for so long to get this to work, but I just can't.

Here's what I did:

var testvar = document.getElementById('example').style.color;
alert(testvar);

Not only would the alert come up empty each time, but IE reports that "testvar" is undefined. Why isn't it working? And if I'm going about it the wrong way, how can I store an element's style info, such as font colour like in this example, as a variable?

View 5 Replies View Related

Accessing Private Members In Extensions

Mar 2, 2011

I'm trying to create an extensible class with private members.

Suppose I have the following:

Code:

Obviously, only "y" should be available to instantiations:

Code:

But how can I now extend this class and still access the private properties inside the extension?

Code:

How do I access x there? The someOtherFunction extension is part of the prototype, so it should be in the same scope as someFunction, no?

View 1 Replies View Related

JQuery :: Sequencing Operation On Members Of An Array?

Sep 23, 2011

I have an array of divs, and can do a style change on them:

var Ray = new Array("first", "second", "nth");
function bluRay() {
$('#' + Ray.join(',#')).animate({color: '#00f'}, 600);}

( The divs don't share a class, and it'd be code-heavy to add classes for all the necessary variations on this function. )

How to make the operation on the divs sequential, at say, 500ms intervals?

View 2 Replies View Related

Using Code On A Webpage That Lists The Site Members?

May 6, 2011

I am currently using this code on a webpage that lists the site members.

function toggleMenu(objID) {
if (!document.getElementById) return;
var ob = document.getElementById(objID).style;

[code]....

View 3 Replies View Related

JQuery :: Not Working On Public Server?

Jan 5, 2010

My form works just fine when testing on my local machine, but when I upload everything to the public server the form does not validate.

View 1 Replies View Related

Sending Form From Public Computer

Nov 13, 2001

We have a form on our website, which ends up being sent to an e-mail address. The only problem is that some people access this form using public computers. When they press submit , the Internet Mail Wizard pops up and tries to make them setup a new account. Obviously because they are using a public computer we can't have them setting up e-mail accounts on that computer.

View 3 Replies View Related

References Themselves Are Passed By Value

Jul 23, 2005

Is it true that Javascript has no clone() method, to pass an object by copy of value instead of reference?

If I have an object and want to make an array out of all of its instance variables, I can loop through it and pass its values to a new array, and the class instances will be passed by copy and not by reference?

Example 9.3: References Themselves Are Passed by Value

// This is another version of the add_to_totals() function. It doesn't
// work, through, because instead of changing the array itself, it
tries to
// change the reference to the array.
function add_to_totals2(totals, x)
{
newtotals = new Array(3);
newtotals[0] = totals[0] + x;
newtotals[1] = totals[1] + x;
newtotals[2] = totals[2] + x;
totals = newtotals; // this line has no effect outside of the
function.
}

Note that this rule applies not only to pass-by-reference, but also copy-by-reference. You can modify an object through a copy of a reference, but changing the copied reference itself does not affect the object nor the original reference to the object. This is a more intuitive and less confusing case, so we don't illustrate it with an example.

View 5 Replies View Related

AJAX References

Oct 23, 2005

I'm currently engaged on a dissertation which is
investigating AJAX technologies and I was
wondering if anyone had any references that might
shed light on the subject?

I will of course carry out a literature review but
in the mean-time has anyone any (preferably print
based) sources of data on AJAX?

View 9 Replies View Related

Function To Add Members Rearranging Array List When Entered?

Jun 17, 2009

I have a form that is done in php I'm converting it to .NET but the java script has an error. I posted all the code but the error is in the "saveOtherSurvivorValues" function i think. What happens is when you click the "add survivor" link to add a the first survivor and then fill out the information for the first survivor then click add survivor a second time for a second survivor it moves the data from the 1st survivor into different fields to produce in accurate data.

Here is a link to the live form.

[URL]

using System;
using System.Collections;
using System.Configuration;
using System.Data;

[Code]....

View 7 Replies View Related

Function To Add Members Rearranging Array List When Entered - ASP.NET?

Jun 17, 2009

I have a form that is done in php I'm converting it to .NET but the java script has an error. I posted all the code but the error is in the "saveOtherSurvivorValues" function i think. What happens is when you click the "add survivor" link to add a the first survivor and then fill out the information for the first survivor then click add survivor a second time for a second survivor it moves the data from the 1st survivor into different fields to produce in accurate data.

using System;
using System.Collections;
using System.Configuration;

[code].....

View 7 Replies View Related

JQuery :: Making A Private Function Public?

Apr 23, 2009

I've got a plugin which is structured as follows:

(function($) {
$.fn.MyFunction = function(o) {
// Here we have some parameters
return this.each(function() {

[Code].....

So what I'm looking for is how to reference MyExternalFunction from my html script. I've tried simply using MyExternalFunction(index) but I get function undefined.

View 6 Replies View Related

JQuery :: How To Make Function Private Or Public

Dec 31, 2011

This question applies to javascript generally as opposed to jQuery specifically. I want to be able to structure my scripts into classes, then create them using the "new" keyword, but here is the important bit: How do I make a js function private (or public for that matter)?

View 4 Replies View Related

Call A Public Script From A Domain Securely?

Jan 15, 2009

I want to call a script from one domain in another domain. How can I *guarantee* that the page calling the script is from my domain and not some hacker/malicious user?The context is that I'm writing my own commenting system, like disqus or intensedebate. They use javascript to imbed your comments (stored on their site) in your site.

Here's how intensedebate's "generic" approach works: You imbed this code into your page:

Code:

<script>
var idcomments_acct = 'YOUR ACCOUNT ID';
var idcomments_post_id;

[code].....

The problem is that anyone has access to your accound ID by just looking at the HTML source, so anyone can bomb your account...

View 1 Replies View Related

Tracking Non-public Website Through Google Analytics?

Mar 26, 2010

so I figured I can track one page of the private website (intranet) through Google Analytics. The way I do this is by creating a page on a public website with just GA code, then putting a 1px x 1px iframe on the private website.

[Code]...

View 2 Replies View Related







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