| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 75184 | 2006-12-19 08:31:00 | Javascript Guru Needed | Erayd (23) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 507973 | 2006-12-19 08:31:00 | I'm having a bit of a problem with a function I'm trying to write. The idea is to add a prototype method to the String object, to enable it to return the first x characters of the string, and remove them from the original object - kind of like what shift() is for arrays. This is what I have so far: function protoStringShift() { String.prototype.shift = function(n) { var s = this.substr(0, n); this = this.substr(n); return(s); }; }The problem is caused by assigning a value to this - if I remove that line it all works fine, but if I leave it in I get an assignment error. Is there any way of assigning a value to this (or to be more precise, some way of changing the string value that this stores)? I've tried both Google and ##javascript on freenode, but I haven't had much luck. The intended destination is the new ChatF1 software. Cheers, Steve |
Erayd (23) | ||
| 507974 | 2006-12-19 10:20:00 | wrong forums..i think | gum digger (6100) | ||
| 507975 | 2006-12-19 10:52:00 | wrong forums..i thinkNegative. There's tons of help here, eg: His "String.prototype.shift = function" is incorrect. It should be "String.prototype.shift = function = I ask for help but Greg ain't got the faintest idea" function_help = non-existant" |
Greg (193) | ||
| 507976 | 2006-12-19 11:07:00 | Not helpful Greg - I did say 'Javascript Gurus' in the title for a reason. You're right that this isn't a programming forum; I only posted here because I was having trouble finding a solution elsewhere. | Erayd (23) | ||
| 507977 | 2006-12-19 11:13:00 | Not helpful Greg - I did say 'Javascript Gurus' in the title for a reason. You're right that this isn't a programming forum; I only posted here because I was having trouble finding a solution elsewhere. edited |
Greg (193) | ||
| 507978 | 2006-12-19 11:16:00 | Apologies, I guess I'm just a little grumpy this evening. /me edits post. | Erayd (23) | ||
| 507979 | 2006-12-19 11:23:00 | Mine edited too. | Greg (193) | ||
| 507980 | 2006-12-19 11:29:00 | Thanks. Next time I gotta remember to take a few deep breaths before hitting the 'post' button. | Erayd (23) | ||
| 507981 | 2006-12-19 11:31:00 | LOL Well no-one took offence. And if you ask Metz, then he'll make a mockery of us both for being wimpy! :lol: | Greg (193) | ||
| 507982 | 2006-12-19 11:34:00 | Too true, too true. He certainly adds a bit of spice to things :D | Erayd (23) | ||
| 1 2 3 | |||||