Would Emulating Private Variables Like This Be Wrong?
Jan 26, 2007
What do you think about emulating private variables for a class this
way?
function Something() {
var private;
Something.prototype.getPrivate = function() { return private; }
Something.prototype.setPrivate = function(newPrivate) { private =
newPrivate; }
}
var some = new Something("My private");
alert(some.getPrivate());
alert(some.setPrivate("Nyah nyah"));
alert(some.getPrivate());
That way the accessor methods instances are shared among instances of
Something. What do you think?
View 7 Replies
ADVERTISEMENT
Jul 20, 2005
I'm in the middle of creating a project management system for our office, and I was wondering if javascript is capable of emulating drag and drop? This would allow me to do some cool stuff.
View 1 Replies
View Related
Jul 20, 2005
I want to mimic the functionality of IE5.5 onmouseenter and
onmouseleave events, using DOM-standard onmouseover and onmouseout
events. The subject element is a table cell that can contain any
freestyle html. I need to fire some JS when user enters the cell with
his mouse, and fire some stuff when he leaves the area. Unfortunately,
if I use onmouseover and onmouseout events, onmousout is fired when
mouse is over some inner element within the table cell contents. The
only way I currently see to handle this is reading the mouse
coordinates in the onmouseout handler and testing if the mouse is
within the cell boundary box or not. But, I am afraid, user coulf
manage to move the mouse first to some inner element, and then quickly
to a space out of the cell so that onmouseover event attached to that
cell is never fired.
View 1 Replies
View Related
Mar 31, 2007
My web application does user authentication through X.509 digital
certificates in combination with user name and password.
When the user applies for a digital certificate from my certification
authority (CA), I have a VBScript code that generates a public/private
key pair with the RSA algorithm, as well as the certificate signing
request (CSR) in PKCS#10 format. I assume that the key pair should be
maintained by the browser (my application support Internet Explorer
only at this moment). Am I right?
Now, when the user tries to log into his account, I would like to have
my web application receive a digitally signed token from the client.
The token can be the client's username signed with his/her private
key.
Since this signing process will happen on the client side, it can only
be handled by client side script, for example, JavaScript.
But, how do we get access to the private key with JavaScript?
View 2 Replies
View Related
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
Feb 16, 2009
I want to be able to set a property on a private object by giving the not notation path to the value. The difficulty is that this object is within closure so I can't access it directly to set the value the normal way (eg. dot.notation.path = 'new value'). This seems weird but I can't think of the obvious way.
Example:
// setter function
function set(path, change){
var privateObject = {
a: 'a',
[Code]....
View 1 Replies
View Related
Oct 8, 2007
I am using the module pattern and private/public methods. I'm having a problem where the private method is using setTimeout() to call itself recursively, but I can't get the syntax right. Code:
View 1 Replies
View Related
Aug 18, 2010
i have something like this:
Code:
var o = {
f1:function(a) {
[code]....
View 4 Replies
View Related
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
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
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
Aug 7, 2011
I'm trying to emulate exactly how a div with the attribute contentEditable = "true" would operate using a textarea...trying and failing. I found some code somewhere which attempts to do something like his but it isn't working well for me.
I want to do this without jquery and with javascript only. The best example I can think of is Facebook's text area that you use to write on somebody's wall.
Here's my sizing function
Code:
And here's my text area:-
Code:
View 1 Replies
View Related
Jan 13, 2010
I am trying to create a private chat from hacking some opensource chat room.I am trying to use some basic AJAX (noobie) to insert a field into a mysql db.It is doing what I want it to do mysql wise but it also changes the url.
my site runs like this. There is a page called private.php with all the php in. private.php has a switch statement to call other pages (the default is home.php).so if a user say clicks contact the link would be private.php?mode=contact.and then in the private page the switch statement would
case "contact":
require("contact.php");
break;
so the user has searched another user and wants to chat.the url at the moment is private.php?mode=full_profile&id=101 in the full_profile.php page I have the ajax in the head and a submit form to call the ajax function.
here is the ajax code
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
[code]....
now the mysql query runs fine. the problem I have is that when I click the submit the url changes to private.php?x=18&y=28 . (the x and y vales are different everytime I click the submit).can anyone tell me where the x and y values are coming from and also why the ajax function is changing the url as the whole point of using ajax is to avoid that.
View 9 Replies
View Related
Mar 14, 2009
I'm using the standard module pattern and the problem is once you set a private variable, trying to test that object independently becomes a nightmare as the next test is polluted by the actions of the previous.So, the options are to have some reset method (which is horrible), setters on everything (defeats the point) or delete object and re-load script (hideous).
View 2 Replies
View Related
Aug 3, 2006
I'm trying to do something, but I don't know if it's possible.
Basically, I want to have a public static class method that could
access a private object's method. I would like to be able to do :
Class.method(InstanceOfClass);
The method would then access a private function from Class by doing
something like
function method(param) {
param.privateMethodOfClass();
}
I've done a lot research and experimentations but just can't come up
with a solution... I don't even know if what I'm trying to do is
possible.
View 4 Replies
View Related
Jul 23, 2005
if I put the line:
var T = new Array(-1);
anywhere in my script, it stops working. e.g
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var T = new Array(-1);
document.open();
document.write('hahahah');
-->
</SCRIPT>
doesn't produce any output. If I change
var T = new Array(-1);
into
var T = new Array(1);
or
var T = new Array(-1,-1);
everything works fine again.
Same results in Mozilla 1.7.2 as in IE 6.
Is that a bug in both their javascript interpreters or can anybody
give me a good explanation of why that is?
View 4 Replies
View Related
Oct 15, 2005
i accidentally set up my path variable instead of classpath and now my
computer can't find any of the executable files. it would be great if
anyone knew what really should stand by the path variable. i don't
suppose there's something like 'set all to default?
View 4 Replies
View Related
Oct 2, 2010
On this site [URL].. I have a JQuery powered search function (the lens button in the menu), when I click on it the search button opens but the close button does not work, how can I fix that?
View 1 Replies
View Related
Feb 18, 2009
Why is my function returning the wrong value??
View 1 Replies
View Related
Jul 17, 2007
function agregar_row(){
for (i=0; i<10; i++){
row="row/" . i;
if (document.getElementById(row).style.display=='none'){
document.getElementById(row).style.display=''
i=11;
} }}
This function is intended to make visible a row, just one by each time the function is called. the way im invoking "(row)" is wrong, i think...
View 3 Replies
View Related
Sep 19, 2011
I'm trying to make my timeclock for work, and the Date object in Javascript is giving me wrong values. I made sure that the time on my computer is the actual time, day and year, yet I either get dates that are 2 week in the future, or set in the year 2403. I have no idea what's going on, even if I just alert out a new Date() with no variables, I get the same result. If there is something that I'm not declaring or anything, I'd love to hear what it is.
View 2 Replies
View Related
Jan 9, 2006
I am relatively new to js, but I did think I was starting to get the
hang of it. Then this happened...
I have a form with an onsubmit event handler:
<form id="uploadForm" method="post" action="..."
onSubmit="checkDates()">
The event handler does some minor validation, then returns true or
false:
function checkDates(y, m, d) {
if (endDate.getTime() >= startDate.getTime())
return true;
alert("Start date must precede end date");
return false;
}
(The arguments to the function are used when it is called elsewhere,
not as onsubmit.)
I also have a library class which needs to process the form submit, so
it hooks onsubmit like this:
MyClass.setOnSubmit = function(listId) {
var list = document.getElementById(listId);
var form = list.form;
var f = form.onsubmit;
if (typeof f == "function") {
form.oldOnSubmit = f;
form.onsubmit = function(){
var ok = this.oldOnSubmit();
if (ok)
return MyClass.onsubmit(listId);
else
return false;
};
}
else
form.onsubmit = function(){MyClass.onsubmit(listId);};
}
My problem is that the value returned from oldOnSubmit and stored in ok
appears as 'void'. This happens in IE 6 and in FireFox 1.07. Can anyone
explain what's happening?
View 8 Replies
View Related
Feb 27, 2006
I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using Javascript & DOM'.
function aKeyWasPressed(e) {
if (window.event) {
var key = window.event.keyCode;
} else {
var key = e.keyCode;
}
alert('You pressed the key: ' + String.fromCharCode(key));
}
It is example of adding an eventlistener to a textarea. The events works alright, but when I press 'a' the alert gives me 'A', when I press Ǝ' I get 'h', when I press Ɔ' I get ''', when I press 'à' I get Ɔ', .... Has probably something to do with the fact that I don't live in the UK or
USA. But it shouldn't matter; a key is a key.
View 3 Replies
View Related
Jul 20, 2005
I have a function for totalling decimal values provided in textboxes
that form a column on a webpage. This script should total the values
in the textboxes, displaying the result in the final
'optotalprogtime' text box formatted as a decimal.
Here is what I've got so far, but I'm getting annoying "object
expected" errors on the line where I attempt to format the number (as
indicated by the comment below)
//realtime calculation formating as minutes (decimals)
function opprogtotalcol() {
alert("in opprogtotalcol");
document.getElementById('optotalprogtime').value = 0;
for (var rowNumber =1; rowNumber <= 12; rowNumber++){
document.getElementById('optotalprogtime').value =
parseFloat(document.getElementById('optotalprogtim e').value) +
parseFloat(document.getElementById('opprogmin' + rowNumber ).value);
}
if(!isNaN(document.getElementById('optotalprogtime ').value)){
//only works for numbers
document.getElementById('optotalprogtime').value =
formatNumber(document.getElementById('optotalprogt ime').value,
2);//format number here
}
}
Any insight would be appreciated.
To head off concerns about wrapping code correctly, my code is
wrapping pretty bad in this form, but in the acutal page I have long
lines that do not wrap.
View 3 Replies
View Related
Jul 20, 2005
I have tried to write a wait function but it seems like it will not brake the while loop. I tried two different solutions. Can anyone tell me what I am doing wrong, and come with another suggestion? If I call the function like this: wait(500); it should wait 500ms right?
function wait(time) {
while(1){
setTimeout("break;",time);
}
}
function wait(time) {
var flag=0;
while(flag=0){
setTimeout("flag=1;",time);
}
}
View 2 Replies
View Related
Aug 23, 2011
I am new to jQuery and I am reading this book as an introduction. I find it very good, but I came across an example today that doesn't make sense to me. It is an example of the prev() method and is like this:
$("h1").prev() // Sibling elements of <h1> tags
Is this correct? I thought prev() just picked one element so it should be "element" instead of "elements" in the comment. Alsoa sibling of <h1> tags would have to be another <h1> tag wouldn't it? And there are no <h1> tag before all <h1> tags?
View 2 Replies
View Related