JQuery :: How To Create Prototype And Custom Object
Apr 17, 2010I am newer in Jquery. How to create the prototype object and custom object in Jquery.
View 2 RepliesI am newer in Jquery. How to create the prototype object and custom object in Jquery.
View 2 RepliesWhat I have been doing so far to make a "class"/Reusable object is this:
PHP Code:
function Dog(){
this.name name;
this.bark = function(){
[code]...
However, recently I have been reading a book on Javascript and it said that the problem with this way of doing it, is that the bark() function will be loaded into memory for each Dog object created this way, while the body of that function is the same for each object.
- A Person class with a name property and a jump() method.
- An animal class with a isMammal property and move() method.
- A Dog class with a numberOfLegs property and a bark() method which is a subclass of Animal (thus inherits the isMammal property and move() method.
- Each of those classes in its own file.
This book I've been reading is actually pretty good, but at some points it's explanation is not rich enough.It explains that functions are objects and that objects in javascript are just key-value pairs. It says that each function has a prototype property which points to a blank Object(), but you can make it point to something else? or maybe I misunderstood it. I still don't understand how it really works.
According to ECMAScript, the root of the prototype chain is Object.Prototype. Each object has an internal property [[Prototype]] that could be another object or NULL.... However, it also says that every function has the Function prototype object: Function.Prototype, it confused me, because a function is an object, for a function object, what is its function prototype and object prototype..For example:
var x = function (n) {return n+1;};
what is the relationships of x, Object.Prototype and Function.Prototype
I am trying to get to the bottom of javascript object, prototypes etc. I have a fairly good grasp of it, but I get confused the closer I get to the base object.prototype. FIrst of all, I was under the impression that all objects descend directly from Object. But some objects (like Array) seem to inherit properties and methods from the function.prototype. So does this mean that the chain is like this:
object -- function -- array Second, I noticed (on the mozilla javascript reference site that object.prototype inherits properties and methods from function.prototype and vice versa!? How can this be? I must be missing something important about understanding the chain?
How would I go about copying all the prototype functions AND the constructor from one object into another object, and then call them?
I know I can use this.example.call(this), but that's not an acceptable solution. I want to deploy this style over dozens, potentially hundreds of objects.
QUESTION ONE: When is use of the jQuery prototype object appropriate, and when is it not?
BACKGROUND:I am still trying very hard to identify the error that is prohibiting me from incorporating a jQuery plug-in into my site in a manner similar to the way that the author of the plug-in has incorporated it into his.Although I have sought consultation with the author, he appears uninterested in working with me.My still fledgling knowledge of jQuery tells me that the author of the plug-in and my implementation of his plug-in are constructed differently.Whereas I use jQuery's prototype property to reference my method and then assign my method anonymously to my HTML document as follows: $().myJQMethod().The author of the plug-in does something very different.I have extracted from the author's plug-in and my implementation of it. Links to the source pages have been included.
CONSTRUCT A (The jQ_Impromptu Plug-In):
(function($) {
$.prompt = function(message, options) {
})(jQuery);[code]...
QUESTION TWO: Although I am able to implement the author's method, it is not performing as it should. When the alert box appears with focus the hosting HTML page is suppose to show through with dimmed opacity.My implementation does not achieve this effect. Firebug has alerted to me to the following breakpoint, but I am poorly unable to interpret it.
How do you create custom jQuery functions? I've tried numerous tutorials on the net and everyone results in firebug saying my function doesn't exist.
Is this the correct way to define a custom jQuery function:
Code:
I am using Tablesorter to work with a simple table, but have comeacross an interesting difference in how it works between browsers.One of my columns looks like this:
Row 1
img src="http://dssweb/apdashboard/images/Green.png"
class="client_status" title="1. UAT testing Sept 09"
[code]....
I want to create a interactive map viewer likeGooglemaps using my own custom map image. On clicking a location on the map, a small popup displayed showing some data. I aslo want a zooming and panning functionality. note that i am using aLinuxserver. The application must not use flash.
View 1 Replies View RelatedIn the following example PositionedRectangle is a subclass of Rectangle, all 3 methods of prototype inheritance seem to produce the same results, method 1 is from the authors book (Flanagan's Definitive Guide 5ed) example 9-3, and method 2 is from his website example 9-3, and method 3 is my own;
// method 1 seems most complicated
function heir(p) {
function f(){};
[code]....
Actually the selector works in this form:
$objects = $("dl\:object",contextelement)
but not in this form: $(element).children("dl\:object").I don't care that it doesn't work in the second, because I only need one time access, since I replace these custom elements with valid html using javascript, as soon as the page loads (sort of like xfbml I guess).My concern is that it DOES work even in IE, which only returns a tagName of "object" from <dl:object>. (given the following html attribute: <html xmlns:dl>). So I'm suspicious. I've tried following the code that matches the selector, but I can't do it, it's too complex for me to follow in a reasonable time.
Lets say we run: window.alert = function() { };
Is there anyway to 'restore' the original alert() method or is it gone
forever?
I know you can do window.alert = Window.prototype.alert, but lets say
you also set Window.prototype.alert = function() { } or lets say we're
in Opera, which doesnt have a Window "class".
I wanted to add an object as a prototype to separate my methods more
nicely, however, I ran into a couple of problems. Apart from the
obvious "scope" issues I found that any instances of my class shared
the objects methods and properties.
I realise (now) that this is actually how prototypes work, they share
functions and objects rather than create new instances of them for
every "class", but is there any way around it? (or shouldn't I be doing
things like this at all?) Code:
I am working on my own pop up calendar, mainly because the one I am currently using crashes the Safari browser at times.
So, I want to verify that what I am doing will work, in that I want to be able to have multiple calendars open at the same time, each independent of the other.
So, I start it off with:
var Calendar = {
dateSelected: null,
topPos:null,
leftPos:null,
somefunction:function(e) {
...
}
};
If I create more than one calendar object, will they have their own variables, in that the dateSelected, topPos and leftPos will be unique to that instance?
Or, is there a better way to do this, that is cross-platform.....
I'm trying to create a function to show a custom message as a tooltip when a user hovers over a table row.
My tr tag looks like this
The javascript function looks like this:
jQuery seems to be loaded correctly, as I get the alert. I don't get the tooltip, however.
What I'm trying to do, in case this is totally retarded and impossible to see, is to hover a tooltip over the clicked row instead of passing it in as a variable.
I have a tag <object> in a page..
"<object type="application/x-my-app" id="", I_rc_3D_c, "" width="100%" height="100%">", "<param name="platformKey" value="",Platform_Code_c,"">",
...
"</object>"
and the jquery1.4.4 JS api library..
The problem is that when the page is loading the first time this object is loaded several times..
I've created a new class using prototype.js. After I make the ajax.request all references to this.myClassMethodorVariable are lost. Does the ajax method blow out the object persistance? I'm fairly new to OOP javascript so could be (and probably am) overlooking some detail. Code:
View 45 Replies View RelatedAs far as I know, there's no event for which a text in a textarea is highlighted. For instance, I want an event to fire when the word "your" in the textarea below is either clicked, highlighted, or brought into focus. HTML Code: <textarea> This is a text area... your text here
View 1 Replies View RelatedIm trying to create a custom selectbox and Im having some problems, with it. What Im trying to do is have a function that loops through all <select> tags and find ones that only have the class name of "select" and then from there they get a custom select box. From there I have a variable passed in order to get the option. I created a few elements and etc... So at this stage Im just trying to get the text from the <option> tag within each individual <li> element and I can't get it working.
View 9 Replies View RelatedI have a table (tables are for tabular data) with patient information. The user can click the row to select it and when they do the right part of the interface loads some additional information on the patient - quick lookup info if you will, but also provides links to tasks involving that information - edit, view case history, etc.I'd like to replace the default right click behavior on the rows to create a pop up menu next to the point of click that links to the same list of options for the convenience of the more savvy users.The project is being built with prototype so no jQuery please. The site is a corporate intranet where Firefox is the only browser it is *required* to work in. It would be nice to have it work in webkit.
View 4 Replies View RelatedI find the JavaScript's Object.prototype and getter/setter mechanism
very nice. However, I need some help with extending an object with
getters/setters in the derived class. For example:
A : function () {}
A.prototype =
{
a : null,
get a : function () { return a++; }
};
B : function () {}
B.prototype = new A;
Now, I would like to define a getter/setter in B. How do I do that?
There is no way to use the same syntax as in "A.prototype = ..." above.
I was hoping I could do something like this in javascript:
var a = {x:1, y:2};
var b = {x:2, z:3};
b.prototype = a;
And then:
b.x => 2
b.y => 2
b.z => 3
The purpose is to set up "b" as an override of "a".
I know it doesn't work that way because "prototype" is not a magic property on any object but constructors only. Is there a way to implement the above without involving a constructor?
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);
in UML? I just found that UML is actually very class-based. It's
difficult to depict the relationship between a constructor function,
its prototype property, and objects that are created using that
constructor function using UML.
Have any of you ever attempted this? How would you do it?
As I know,it's not well to extend Object.prototype derictly.
In the Prototype(JS Framewoke),there is no extend Object.prototype.
It only add some static method for Object class.I want to konw the reason.
I have the following nested javascript collection (below) and I'm trying to access the information within the collection using prototype so I can properly style and layout the data.
var teams = {
"team1:" {
"QB": "Alexander Hamilton",
"RB": "John Jay",
[Code]....