Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20553 > unrolled thread
| Started by | Lukas Bombach <lukas.bombach@googlemail.com> |
|---|---|
| First post | 2013-07-05 09:35 -0700 |
| Last post | 2013-07-05 20:30 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.javascript
Find out if a variable is a Selection Lukas Bombach <lukas.bombach@googlemail.com> - 2013-07-05 09:35 -0700
Re: Find out if a variable is a Selection Lukas Bombach <lukas.bombach@googlemail.com> - 2013-07-05 09:38 -0700
Re: Find out if a variable is a Selection Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-05 20:30 +0200
| From | Lukas Bombach <lukas.bombach@googlemail.com> |
|---|---|
| Date | 2013-07-05 09:35 -0700 |
| Subject | Find out if a variable is a Selection |
| Message-ID | <b7bf07a2-3bf3-46a4-a792-a30e309a81de@googlegroups.com> |
Hi, I'm writing a function to save and a function to load a selection. In the save function I simply return window.getSelection() . The load function is tricky. It takes all kinds of parameters. Inside the function I'm trying to figure out what has been passed and make a selection accordingly. That means I can pass it (10, 20) to make a selection from characters 10 to 20, some other stuff and last but not least I should be able to pass it a Selection object. Now I'm wondering how I can find out if a Selection object has been passed — cross-browser, at best until IE 8. I've read a very thorough post on Stackoverflow [1] and my best should would be to to use "instanceof Selection". But doesn't seem to be very stable when it comes to cross-browser issues. It works in Chrome/Safari and FF3.5+, but I can't test IE right now. However, even if it works in IE, can I be sure (more or less) this will stay like this in the future. Are there standards and specifications on this? Or is there another or even "right" way to do this? Thank you Lukas [1] http://stackoverflow.com/questions/332422/how-do-i-get-the-name-of-an-objects-type-in-javascript
[toc] | [next] | [standalone]
| From | Lukas Bombach <lukas.bombach@googlemail.com> |
|---|---|
| Date | 2013-07-05 09:38 -0700 |
| Message-ID | <040ffae9-be35-4f9b-a02c-62b78782ea0a@googlegroups.com> |
| In reply to | #20553 |
Ok, IE fails instanceof Selection On Friday, July 5, 2013 6:35:08 PM UTC+2, Lukas Bombach wrote: > Hi, > > > > I'm writing a function to save and a function to load a selection. In the save function I simply return window.getSelection() . The load function is tricky. It takes all kinds of parameters. Inside the function I'm trying to figure out what has been passed and make a selection accordingly. That means I can pass it (10, 20) to make a selection from characters 10 to 20, some other stuff and last but not least I should be able to pass it a Selection object. > > > > Now I'm wondering how I can find out if a Selection object has been passed — cross-browser, at best until IE 8. I've read a very thorough post on Stackoverflow [1] and my best should would be to to use "instanceof Selection". But doesn't seem to be very stable when it comes to cross-browser issues. It works in Chrome/Safari and FF3.5+, but I can't test IE right now. However, even if it works in IE, can I be sure (more or less) this will stay like this in the future. Are there standards and specifications on this? > > > > Or is there another or even "right" way to do this? > > > > Thank you > > Lukas > > > > > > > > [1] http://stackoverflow.com/questions/332422/how-do-i-get-the-name-of-an-objects-type-in-javascript
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-07-05 20:30 +0200 |
| Message-ID | <2589620.ThK4HsqIrX@PointedEars.de> |
| In reply to | #20553 |
Lukas Bombach wrote: > I'm writing a function to save and a function to load a selection. In the > save function I simply return window.getSelection() . The load function is > tricky. It takes all kinds of parameters. Inside the function I'm trying > to figure out what has been passed and make a selection accordingly. That > means I can pass it (10, 20) to make a selection from characters 10 to 20, > some other stuff and last but not least I should be able to pass it a > Selection object. > […] > Or is there another or even "right" way to do this? The right way in languages as dynamic as these is either to use Duck Typing (feature tests). Or not to overload parameters when you cannot reliably tell the types of possible arguments (apart) (such as with host objects); IOW, to provide *several* functions/methods with descriptive names for each such undetectable/indistinguishable type. The right way includes not to top-post and not to use Google Groups for posting, at least until they have fixed the numerous bugs. <http://jibbering.com/faq/> <http://PointedEars.de/faq> -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web