How To Understand The Javascript Class Model?
Aug 25, 2005
I have got some confused problem when I try to write some custom object by javascript.
Look at the example code here:
<BODY>
<script language="jscript">
function Class()
{
this.member = null;
this.event = null;
this.memberFunction = function()
{
alert("memberfunc" + this.member);
this.callEvent();
alert('after call');
}
this.callEvent = function()
{
alert("call:" + this.event);
if (this.event)
{
this.event();
}
}
}
var obj = new Class();
obj.member = "hello";
obj.event = function()
{
alert('event');
}
obj.memberFunction();
</script>
<button id=hello >click</button>
<script>
hello.onclick=obj.memberFunction;
</script>
I try to define a javascript class and define a event handler for it. There is a member and a memberFunction and a event in the Class body. Then I created a object (obj) of Class and defined a event handler like this:
obj.event = function()
{
alert('event');
}
When I call the function: obj.memberFunction(); the event handler was
fired and alert a message ('event'). But when I try to use a button to fire the event, it doesn't work. It seems we have lost the member function callEvent, it is a undefined value, the same as this.event member.
View 1 Replies
ADVERTISEMENT
Oct 23, 2007
A very brief background before my question - I run a forum where it has recently been reported that the signature used by one of the members includes a URL which is reported by Kaspersky antivirus to contain some malware, specifically "Trojan-Downloader.JS.Remora.w" (a trojan about which I can find very little information). Well, I didn't have anything better to do yesterday so I thought I'd take a deeper look into this and, while taking some precautions, did indeed find some obfuscated JavaScript on the page in question. I should state at this stage that I'm not a programmer but after a bit of Googling discovered that I could de-obfuscate (is that a word?) the code using an online script which turned it into something fairly readable. However, as I say I have virtually no programming knowledge and what the code does, or attempts to do, is completely beyond me, although from what I read yesterday I believe that the JavaScript functions uncovered are probably designed to create another bunch of JS code which actually does the damage.
Having come so far I'm now really intrigued to find out what the code does but I don't have the knowledge to go that one final step. My question here is simply is this an appropriate place to post the code and ask if anyone can explain it? I'm aware that as this looks like something undesirable there may be good reasons for not posting it and if that's the case does anyone know where might be a more appropriate forum? Alternatively, if anyone wants to take a crack at it individually please let me know and I'll be happy to send through what I've come up with.
View 4 Replies
View Related
Jul 23, 2005
In the code below, I want to add a handler to a *row* (eventually so I can
change the style of a row), but the event is being generated by the TD's it
seems - in Opera and IE. Is there another way to assign a handler, making
sure the event will come from the row and not a TD, or is this simply a box
model issue I cannot work around by assigning new handlers? Code:
View 3 Replies
View Related
Jul 23, 2005
I am looking for a reference to the Document Object Model interface for
Javascript, preferably in HTMLHELP format. Do you know of any such reference?
View 5 Replies
View Related
Sep 10, 2010
I am working on a project and in that I have to create:
Image-map tooltip (Mouseover) + Model window (On Click)
View 5 Replies
View Related
Jul 23, 2005
My original idea of two trains, however pictural it was, appeared to be
wrong. The truth seems to be even more chaotic.
IE implements its standard down-up model: any mouse event goes from the
deepest visible element to the top. By carefully studying fromElement
and toElement properties, one can handle events on any point of their
way up.
NN/FF implements a "Russian hills" style: mouse events go first
up->down (window->deepest element), and right away after that it goes
down->up (deepest element->window). On theory you can handle events
during any phase on any level. On practice this implementation has some
major flaws. I don't have NN handy right now, but in FF we have:
View 9 Replies
View Related
Feb 13, 2011
What can I do to find out what the errors in the error console mean?
View 7 Replies
View Related
Oct 22, 2011
success(data, textStatus, jqXHR)Function, Array A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object.
'success': function(html){ jQuery("#quote-of-the-day").html(html) }
success: function(data) { var out = "<ol>"; $(data).each(function(){ out+="<li>"+this.title+"</li>"; });
The above 2 ways of defining the success call back confused me.
1) According to definition, it should take 3 parameters, why here it only takes 1 parameter?
2) Why the name of parameter passed into function() can be different? Does this name matter?
View 5 Replies
View Related
Apr 3, 2006
I discovered this syntax on the google example of a client to their web
service.
function PagClass()
{
this.init();
}
PagClass.prototype = {
init : function() {
this.m_bInited = true;
this.m_nTotalRows = 0;
this.m_nFirstRowNum = 0;
this.m_nRowsPerPage = 0;
this.m_nNumPages = 0;
this.m_nReportid = 0;
this.m_nResultNumStart = 0;
this.m_strStart = "";
},
foo: function() {...},
bar: function() {...}
}
This seems like a very elegant way to create classes in javascript,
gives you a constructor and lists methods as comma separated
properties.
My colleague is suspicious that there may be excessive runtime overhead
associated with the prototype, property list way of doing this.
Anybody know for sure?
View 1 Replies
View Related
Jul 23, 2005
I have several tags on a webpage of the same class. If the user clicks a
specific checkbox I'd like to be able to alter the display property of the
class, affecting all objects of that class.
This is an intranet application so we know that javascript will be enabled
and the browser will be IE.
How can I affect all the members of this class? Is there a way I can toggle
the DISPLAY property of a class so all the elements using that class would
be affected? Code:
View 3 Replies
View Related
Jan 19, 2006
Modello is a lightweight framework that enables you to write JavaScript class like other class-based object-oriented programming language. It introduces class, class-based inheritance, multi-inheritance, private members, RTTI and more into JavaScript. Modello can help you write more readable, reusable and maintainable JavaScript code.
View 2 Replies
View Related
Aug 23, 2006
Can you call a java class from within a javascript?
View 1 Replies
View Related
Dec 11, 2003
I have following css code in a html file:
<style>
.myClass { color:red; }
</style>
How can I extract the value of the property "color" from the class "myClass"?
Pseudo-code (which of course doesn't work), so you get the idea:
<input type="button" onclick"alert('The CSS color is '+document.style.myClass.color)">
View 3 Replies
View Related
Mar 24, 2010
jquery provides ajaxStart() and ajaxStop() events. Those two events do not seem to be triggered if the ajax requests are made by Microsoft Ajax tool Kit (from ASP.Net code). Is there any way to bridge those two event models? If not currently possible, is there any future initiative or plan out there to make this happen?
View 2 Replies
View Related
Jun 21, 2009
iam either being really dumb or something is way wrong with the code. i am trying to create a fade in / fade out effect. i know there are tons of scripts out there that do this, but i like to do it myself. my script is only working in firefox at the mo (when it works il cater for other browsers). basically i can get the fade out part to work, but when i want to fade back in it does nothing. now logically id of thought that fading in would be the same as fade out but reversed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
[code]....
View 2 Replies
View Related
Sep 7, 2011
I don't really undertand what do $("#" + this) and $("#" + i) mean. What's the meaning of "#"? I don't understand too why the first each() function stops at "three". I think it should be return (this == "three"); instead of return (this != "three");.
<!DOCTYPE html> <html> <head> <style> div { color:blue; } div#five { color:red; } </style> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <div id="one"></div> <div id="two"></div> <div id="three"></div> <div id="four"></div> <div id="five"></div> <script> var arr = [ "one", "two", "three", "four", "five" ]; var obj = { one:1, two:2, three:3, four:4, five:5 }; jQuery.each(arr, function() { $("#" + this).text("Mine is " + this + "."); return (this != "three"); // will stop running after "three" }); jQuery.each(obj, function(i, val) { $("#" + i).append(document.createTextNode(" - " + val)); }); </script> </body> </html>
View 4 Replies
View Related
Dec 17, 2001
how the class attribute works in CSS: I can specify that every attribute with class="foo" be italicized with: .foo {font-style: italic;}
What if I want to do the same sort of thing in Javascript? Is there something built-in like document.GetElementsbyClass("foo").style = "italic" (I'm just making this code up of the top of my head, I don't know how javascript works.)
It seems to me that with JavaScript you're supposed to use the name="" attribute instead of class="". Why the diference?
I looked at webmonkey that had an article about this, but their writing style is simply confusing and I can't make heads or tails of their articles.
View 1 Replies
View Related
May 6, 2009
I am using a very simple search-type page to enable users to input a model number and its page appears in a inline frame. Its not a true search as it is simply relying on a person entering the correct html page name to find it. But this works perfectly in my application.The problem I have is that I cannot get the type box to accept enter key as a submitt, only a click of the mouse will submitt the request. If enter is pressed the box loses the users input but no action is taken.I think this may be a javascript issue. I have posted the code below.
[CODE]
<html>
<head>
[code]....
View 2 Replies
View Related
Jun 3, 2010
My code: [URL]... When I click on UpraviƄ in class edit I need add some HTML code to begin and to end of class entry how to I can select class entry in the same class post on which I clicked?
View 1 Replies
View Related
Mar 7, 2007
Here we are facing a problem which is when we pass a parameter to javascript putting '&' . Ex: &contact.
In Japanese OS when we receive this parameter in the script '&' is converted to 'e'.So script is not recognizing the same. In english OS this working fine.....
View 1 Replies
View Related
May 5, 2011
I have a huge blob of code but the main part I am focusing on is this
$('.billboard_click').click(function () {
//this remove class
$(".billboard_click").removeClass("billboard_click");
});
1. Execute a click event when the div with the class 'billboard_click' is clicked
2. Once clicked, remove the class from that very div to avoid another click from happening
3. Execute a series of events such as animations, etc
4. add the class back to the clicker div
The code does not seem to work as expected but I am wondering if I am having issues elsewhere at this point and wonder if this actually is known to work
View 7 Replies
View Related
Mar 28, 2010
I'm using jquery to make it easy for AJAX calls.
So I create a class: function cMap(mapID){//vars and stuff}
I go and prototype a function: cMap.prototype.loadMap = function(){ //jquery AJAX call }
Now in the jquery $.ajax({...}); call, I use an anonymous function on the "success:" call: success: function(data){ this.member = data; }
My problem is that inside this anonymous function call I'm trying to call a class member of my cMap class to store the data in from the AJAX call, but it's out of scope. So the JS console in FF/Chrome throws errors about bad value/doesn't exist.
How can I access this class member from inside an anonymous function? Or at least what's a good way to go about doing all this?
View 2 Replies
View Related
Jul 2, 2009
I am new to this discussion but hope you would post reply for my query and encourage me to keep in touch with this discussion. Well here is my problem. I have made an edit in place form in which we can add and remove the elements. I have used jquery.jeditable.mini.js and jquery.duplicate-remove.js plugins for edit in place and add and remove action. I have live() function to access the dynamically ganerated elements like this. $(".addressDiv span").live("mouseover", function(){
clickable function here...
[Code]...
View 1 Replies
View Related
Sep 27, 2011
CONDITIONS:If a person selects a Friday Class but not a Saturday Class the Total Cost Field will automatically enter $99.If a person selects a Saturday Class but not a Friday Class the Total Cost Field will automatically enter $99 as well.If a person selects both a Friday & Saturday Class the Total Cost field will automatically be $159.I found the following code and so far only have it changing when a Friday class is entered. I have no idea where to go from here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
[code].....
View 10 Replies
View Related
Dec 29, 2011
I am adding a CSS class to a DIV as follows:$div.addClass("Hover");But I would like the class to be added only if the DIV does not have a class named "Disabled".
View 2 Replies
View Related
Dec 22, 2010
I have this filter in a results table that also reflect in a ui datepicker day styling (ex:available unavailable) . Everything fine till i change month or year in datepicker . Maybe i have to use live() or livequery() but can see the way .This is the code:
$("#filterSelect").change(function(){
var filtro=$("#filterSelect").val();
$("#filter-box2").val(filtro);
[code]....
View 1 Replies
View Related