Extended The String Prototype?
Apr 3, 2011
I extended the string prototype with the following.
String.prototype.equalTo = function( str )
{
return this.toLowerCase() === str.toLowerCase();
}
I'm worried about special characters and double byte characters.what I should be looking out for? or doing?
View 2 Replies
ADVERTISEMENT
Apr 27, 2004
I couldn't find a single thread with the creme de la creme of String prototype extension methods, so I figured I'd start one. Here we go!
String.prototype.lTrim = function () {
return this.replace(/^s+/gm, "");
}
String.prototype.rTrim = function () {
return this.replace(/s+$/gm, "");
}
String.prototype.trim = function () {
return this.rTrim().lTrim();
}Obviously, this one's easy to understand. I'm using multi-line mode so as only to get rid of spaces and tabs before and after words. Single-line mode would replace any newline/carriage return characters as well.
String.prototype.capitalize = function () {
return this.replace(/[a-z]/g, function (str, n) { return str.toUpperCase(); });
}
String.prototype.toCamelCase = function () {
return this.replace(/s[a-z]/g, function (str, n) { return str.toUpperCase(); });
}
String.prototype.unCamelCase = function () {
return this.replace(/[A-Z]/g, function (str, n) { return " " + str.toUpperCase(); });
}This is something I needed today, to turn a camelCased variable value into its Header Format. While I was at it, I wrote the un-do-er.
View 8 Replies
View Related
May 10, 2006
I wrote a .repeat(n) function for strings which seemed to work fine:
String.prototype.repeat = function(n) {
// repeats the string n times
if (n<1) return "";
if (n<2) return this;
for (var aStr = [this];--n>0;) aStr.push(aStr[0]);
return aStr.join("");
}
Only I was a little surprised to get "object" (instead of "string")
when I tried:
alert (typeof ("x".repeat(1)));
I fixed this by modifying ...
if (n<2) return this+"";
View 8 Replies
View Related
Jul 23, 2005
Is it possible to get extended privileges for a local application, without asking if possible, like any non/java-javascript app would be able to ?
View 2 Replies
View Related
Jun 20, 2011
I´m using the superfish jquery Module at the website of a costumers. [url] Now the costumer wants that the submenus always where displayed and stay extended! If i chose "other parameters" in the superfish menu options i can enable Expand Menu. But my menu is still not expanded! Nothing happens! Is there a easy possibility to do this? I am using Joomla 1.5 with the latest Updates!
View 2 Replies
View Related
Nov 25, 2011
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
View 5 Replies
View Related
Dec 14, 2009
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?
View 24 Replies
View Related
Dec 25, 2010
I want to know if there is a way to return ajax call as html value and not plain text, ie all html formatting will be displayed.
My code:
<script src="jquery.js">
<script>
$(function()
{
[Code]....
String returned from webform4.aspx is html formatted but jquery displayed it as plain text. Is that anyway to display it as html string ?
View 3 Replies
View Related
Jun 26, 2010
I have a for loop: Code: for( var i = 0; i < aInput.length; i++ ) I want to use this i variable to concatonate it as a string to find an input box
Code:
var j = i;
var qualname = "discountqualifier" + j;
qualname.toString();
if ( inputName == ( qualname ) )
{
Assuming I have a input box named discountqualifier0, discountqualifier1, discountqualifier2 etc...
View 4 Replies
View Related
Dec 2, 2010
I have some jquery code like this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1258" />
[code]....
View 1 Replies
View Related
Oct 18, 2010
I need a simple, quick and efficient way to logically branch if I find a string is contained in another string in jquery Most other languages this can be resolved in one or two lines and it would be readable.
View 5 Replies
View Related
Jan 25, 2011
I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function.callback should be a string so why is it saying otherwise?
View 3 Replies
View Related
Jan 27, 2010
Is it possible to break apart a string into characters, be it a word or a sentence, and store each individual character in an array?
View 11 Replies
View Related
Sep 21, 2010
I have made a basic form, and I need to combine three values within my form, then create an md5 hash of this string.Then assign it to a hidden variable.My form is here...
Code:
<p>
<label for="firstname">First Name: </label>
<input id="firstname" type="text" name="firstname" /><br />[code]....
Or I have created a pastebin of it here, for easy reading: http://pastie.org/1171757.So I need to be able to combine the three values into a string, create a md5 of the string, then call the value of the string into a hidden value all before posting the form.
View 12 Replies
View Related
Aug 24, 2005
I can use "with" like this:
function MyObject(message)
{
this.message = message;
}
function _MyObject_speak()
{
alert(this.message);
}
with (MyObject)
{
prototype.speak = _MyObject_speak;
}
I was wondering why I can't use "with" like this:
with (MyObject.prototype)
{
speak = _MyObject_speak;
}
View 8 Replies
View Related
Jul 23, 2005
One of the complaints about prototype.js (google for it if you're not
familiar with it) is that it's poorly documented. I have this inkling
that the key to understanding prototype.js is in the bind function.
The problem with Javascript is that the "this" operator is poorly
overloaded and it is often hard to understand in the context of
object-oriented javascript
So, let's start with the definition:
Function.prototype.bind = function(object) {
var method = this;
return function() {
method.apply(object, arguments);
}
}
As I read this, it states that all functions (which are themselves
objects) will, in the future, have an associated method called "bind".
The function() function, so to speak, simply instantiates a Function
object with the parameter list and then evals the statement, sticking
the resulting execution-tree in the current code frame.
The "this" there refers to the function object associated with the call
to bind(), right? But the word "arguments" there refers to the
arguments passed to the function object *generated by* the call to
bind().
In every example within prototype.js, bind() is called either in a
constructor or within a method contexted to a javascript object, and is
always called with "this" as its argument, e.g.:
this.options.onComplete = this.updateContent.bind(this);
As I read the code it seems to be stating that the "this" object
referred to within bind()'d functions are being coerced into always
referring to the current instantiated object.
But isn't this always the case anyway? Is this a rather confusing
attempt to ensure "this" purity whereby the call
method.apply(object, arguments)
is forced to always have the reference to the containing object present?
I think I've got it. Bind() generates uniq functions that contain live
references to the objects to which they belong, such that the function
object can then be passed to setTimeout() or onMouseOver(), handlers
that accept functions but not objects.
View 8 Replies
View Related
Mar 15, 2006
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".
View 3 Replies
View Related
Jun 5, 2006
I would like to set up an event observer outside of an object, so I
can't use this.bindAsEventListener. How can I pass the correct object
reference?
I tried something like this, and various other variations, but no luck.
This works when I set it up from inside the object, using "this.",
Event.observe(targetId,'click',targetId.select.bin dAsEventListener(this),false);
View 28 Replies
View Related
Jan 11, 2007
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:
View 2 Replies
View Related
Jan 23, 2007
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.....
View 8 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
May 16, 2007
I want ask you if, for a web portal/application, is better prototype or Jquery? I don't want to innesc some type of flame, but after the announce that drupal use JQuery and that the new Wordpress
2.2 use Jquery I ask myself if my choice of use prototype.js is the bettere choice.
View 5 Replies
View Related
May 17, 2011
I have <div id ="changeable"> with some html in it. I have a link that calls the function to replace the info in the div. The problem is that the "creative_development.inc" file is added to the top of the div and does not replace the content. How do I replace the content, and not just add content?
View 1 Replies
View Related
Nov 20, 2007
I'm trying to make an addEvent function that will automatically attach itself to the object using a class.
My question is how can I add the function so when I write obj.addEvent("click",myfunction); it will add the event?
Here's my current function:
this.prototype.addEvent = function(type,fn)
{
if(window.attachEvent)
this.attachEvent("on"+type,fn);
else if(window.addEventListener)
this.addEventListener(type,fn,false);
}
View 4 Replies
View Related
Dec 13, 2007
I need help to workaround the following problem:
First, about the environment:
- The web pages automatically generated.
- Pages can be inserted to each other
- When a subpage to be inserted is being generated, it does not know will it be inserted or not.
- That because each subpage uses the <script src=...> tags to load the script it needs.
- in the external script files I'm trying to protect it from repeated execution checking (if(){}) the value of a variable which is created after in the script.
Everything worked fine until I tried to use the .prototype to declare the method of my objects.
In the Internet Explorer, I got "Object does not support this property or method", on the access to a prototype function, because the prototype of my object was deleted by itself after the second load of the external script. Code:
View 4 Replies
View Related
Apr 9, 2006
This function will return an array of the elements in a page that contain a certain attribute, you can also give it a value that the attribute has to match, a tag name that the element has to match and a parent element.
I know there are other functions for doing this, but this one is written for use with the prototype (http://prototype.conio.net/) JavaScript library, in fact its really just a modified version of the getElementsByClassName() function that’s part of prototype.
document.getElementsByAttribute = function(attribute, value, tagName, parentElement) {
var children = ($(parentElement) || document.body).getElementsByTagName((tagName || '*'));
return $A(children).inject([], function(elements, child) {
var attributeValue = child.getAttribute(attribute);
if(attributeValue != null) {
if(!value || attributeValue == value) {
elements.push(child);
}
}
return elements;
});
}
Usage is pretty simple, this will return all elements with a width attribute:
View 2 Replies
View Related