JQuery :: Classes - Objects And Inheritance ?
May 28, 2010
Basically i have a good experience and knowledge with prototype.js library and also at the same time i am willing to get deeper into jquery.
I very much use oops concept now a days in almost every problem i solve using javascript, and was doing with prototype's feature to create classes and objects. Since i am now looking to get deeper into jquery, i was looking to find similar feature in jquery as well. I suppose jquery must be having a feature to create classes and do inheritance programming, but i couldn't find the way. My question to the forum is, Is there any option/feature in jquery which helps us to create classes and objects of our own probably with the support of inheritance?
View 2 Replies
ADVERTISEMENT
Jul 23, 2005
I've discovered the following problem while building an APP:
/* Code Start **************************/
// Definition
function cClass_prototype_prototype()
{
this.array = new Array;
this.className = "cClass_prototype_prototype";
}
function cClass_prototype()
{
this.className = "cClass_prototype";
}
cClass_prototype.prototype = new cClass_prototype_prototype;
function cClass1()
{
this.className = "cClass1";
}
function cClass2()
{
this.className = "cClass2";
}
cClass1.prototype = new cClass_prototype;
cClass2.prototype = new cClass_prototype;
oClass1 = new cClass1();
oClass2 = new cClass2();
// Testing
alert(oClass1.array)
alert(oClass2.array)
oClass1.array.push(1);
alert(oClass1.array)
alert(oClass2.array)
/* Code End ****************************/
If you will execute this code you will see that pushing an value into
the first class instance array property cause changing value of the
second class instance array property.
Is it possible to have array values not connected to each other?
I would like to avoid defining "array" property in cClass1 and cClass2
(in this case it would work the proper way) and have them defined only
in third-level parent class cClass_prototype_prototype.
View 2 Replies
View Related
Nov 17, 2009
I posted this once, but it disappeared, and I have no notifications that I did anything wrong. I read the rules before posting and wasn't breaking any so I am not sure why it disappeared but here goes again.
I am trying to learn Javascript (particularly OOP) from a series of screencasts by Douglas Crockford. I have developed a theoretical "game" to build to illustrate it to myself better, and learn by example.
I must be misunderstanding how inheritance works, because my code is not producing the results I thought it would. Here is what I have, followed by an explanation of my understanding. $(function()
[Code]...
View 11 Replies
View Related
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
Mar 4, 2007
In my research in the javascript language I have encountered problems
with implementing prototype inheritance while preserving private
methods functioning properly. Here is an example: Code:
View 2 Replies
View Related
Mar 3, 2005
Suppose I have:
Code:
function A() { ... }
function B() { ... }
What's the difference between:
Code:
B.prototype = A
and
Code:
B.prototype = new A
?
View 5 Replies
View Related
Aug 17, 2006
Let's consider this example:
function Polygon(iSides) {
this.sides = iSides;
}
Polygon.prototype.getArea = function () {
return 0;
};
function Triangle(iBase, iHeight) {
Polygon.call(this, 3);
this.base = iBase;
this.height = iHeight;
}
Triangle.prototype = new Polygon();
Triangle.prototype.getArea = function () {
return 0.5 * this.base * this.height;
};
Here are my questions:
1/ "Triangle.prototype = new Polygon();" : Doesn't this line overwrite all the properties already defined in the Triangle function?
2/ "Triangle.prototype = new Polygon();" : Won't this same line assign this.sides an empty string (or undefined ??) if one considers that the polygon function has no arguments? Or does writing ...prototype = new SomeClass() only "touch on" the methods?
View 2 Replies
View Related
Jul 30, 2010
please bear with my noobishness, but i've been trying for many hours to understand what is going on behind this code:
[Code]...
actually construct an instance of Employee if the reference to its constructor has been replaced by an instance of Person that only contains name and age properties? how is Ken ever initialized by Employee constructor?
View 1 Replies
View Related
Aug 29, 2006
I'm looking to do something like this:
function superDuperObject(range) {
this.startContainer = new superDuperObjectStartContainer(range);
}
function superDuperObjectStartContainer(range) {
this.calculatedContainerNumber = doSomethingAndGetSomethingBack(range);
return range.startContainer
}
function doSomethingAndGetSomethingBack(range) {
return
someCoolInformationThatICalculateInThisFunctionTha tNeedsTheRange;
}
var myObject = new
SuperDuperObject(DOMRangeObjectThatIDefindedEarlie rInCode);
// Show me the startContainer of
"DOMRangeObjectThatIDefindedEarlierInCode"
alert(myObject.startContainer);
// Show me the calculatedContainerNumber that I get from a function
that does stuff with the range passed to it
alert(myObject.startContainer.calculatedContainerN umber);
View 1 Replies
View Related
Dec 29, 2010
What are the benefits of prototypal inheritance over classical inheritance?
View 1 Replies
View Related
Oct 20, 2009
The first div in this example has the position property stated in the div itself.
The second has it stated in a separate style statement, and it doesn't get inherited, though another property from the same style statement DOES.
Firebug makes no complaints.
Is there a better way to refer to the jquery library files, so that you don't have to fix my pointers to my local library?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
[Code]....
View 2 Replies
View Related
Sep 20, 2005
What I am trying to achieve is an 'inherits' method similar to Douglas
Crockford's (http://www.crockford.com/javascript/inheritance.html) but
that can enable access to the superclass' priviledged methods also. Do
you know if this is possible ?
In the following example, I create an ObjectA (variable a), an ObjectB
which inherits ObjectA (variable b) and an ObjectC which inherits
ObjectA (variable c1). The 'toString ()' method of ObjectC refers to
the 'toString ()' method of ObjectA. This is possible because the
'Object.inherits ( superClass )' method adds a reference to the
superClass of an object in the object's prototype.
If I understood things correctly, the prototype is the same for all
objects of class ObjectC. Therefore, I should be able to only add the
reference to the superClass once. That is the purpose of the
'Object.initializedPrototypes' array : it keeps track of the objects
for which a reference to the superClass has been added to the
prototype.
However, when I create another instance of ObjectC (variable c2), its
prototype doesn't contain any reference to the superClass.
A workaround for this problem consists in adding a reference to the
superClass for each instance of the inferiting object (either by
bypassing the check to Object.initializedPrototypes or by adding the
reference to a priviledged member such as 'this.superClass' instead of
'this.prototype.superClass'). However, in terms of memory usage or of
"programming elegance", this seams to defeat the whole purpose of using
prototypes.
Here is the code, if any of you have got ideas...
View 2 Replies
View Related
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
Jul 6, 2010
I am building a menu system and I cannot seem to differentiate between the different class elements in my menu. My problem is that when I click on one of the 'buttona' elements, all the ul's with 'effect' fire - does anybody know how to differentiate so that if the one li is clicked just thecorrespondingul with open and close?
<ul> <li><a class="buttona" href="#">Application one</a>
<ul class="effect"> <li><a href="#">Add</a></li> <li><a href="#">Edit</a></li> <li><a href="#">View</a></li>
[code]....
View 1 Replies
View Related
Jul 22, 2010
I want to use variable names while accessing css classes. Here I am giving example about my query
function ab(temp){
var spc = "horizontal"+temp;
$("#spc .cssClass").css("left","20px");
}
variable temp will change dynamically. as per temp we need to acces horzontal1 or horizontal2 divs.
View 2 Replies
View Related
Jul 21, 2009
I am using nested jQuery UI Tabs in my application. My problem is that I want to style them all differently. I can't seem to get this to work, as they all seem to use the same CSS classes.
Is there some way to get the tabs to use different classes, or some other way to do this?
View 3 Replies
View Related
Oct 21, 2010
We have a need to modify the actual css style definitions dynamically.We can successfully modify css class styles via the following steps. It seems to work fine in ie and firefox.
Does anyone know of a reason it might cause problems?[code]...
View 8 Replies
View Related
Feb 8, 2011
I saw the ui dialog
here is the link[URL]...I tried to use the same it worked the example uses id which will work only for one element , if I want to display multiple diaglogs then id will not work and I have to use classes
[Code]...
View 3 Replies
View Related
Apr 10, 2010
I need to remove class to prevent triggering of click function for elements
Have:
<script type="text/javascript">
$(document).ready(function() {
$('.item1').click(function(){
[code]....
second click on element "blabla" triger again click function. why?
View 6 Replies
View Related
Apr 24, 2009
So I understand you can do:
$(".className").xxx.
Is there an easy way with jquery to have it match 2 classes. So maybe I only want the action to take place it the element has class1 and class2.
$(".class1" , ".class2").xxx
The above is close to what I would like, but thats if any of the 2 classes match, go. I need it to be both. I can probably do this with some basic javascript logic.. just figure there may be a function for this already.
View 4 Replies
View Related
Feb 24, 2010
I'm using the latest version of JQuery. How do write an expression to match multiple classes, but only for elements that are inputs of type="button" or type="submit"? I have figured out how to match multiple classes with the expression .
View 4 Replies
View Related
Apr 30, 2010
Right now I have something of the form in my CSS:
And in my HTML
How do I show all items belong to classes "a" and "b"? Right now I'm trying:
Is this the right approach, or should I be doing something else?
View 1 Replies
View Related
Jun 16, 2009
How do you get the first element when the element got multiple classes?
View 6 Replies
View Related
Dec 20, 2011
Lets say I have something like code...
View 1 Replies
View Related
Dec 3, 2010
I am just starting to learn jQuery. I checked documentation on this and still can't figure this out:Here is my goal:I have these three rowBlocks where I want to make the first and last classes renamed to
"rowBlockTop" and "rowBlockBottom":
<div class="rowContainer">
<div class="rowBlock clearFix">
[code]....
View 1 Replies
View Related
Feb 24, 2011
I have in my [code]...
The intended effect is for spans of class "checkbox", which should each contain one checkbox, to have the class "checked" if the checkbox is checked, "unchecked" if not.
When I load the page and do an "inspect element", the spans have class "checkbox" but none of them have either the class "checked" or "unchecked".
View 7 Replies
View Related