Jump to content

anyone know well the prototype object here?


xbl1
 Share

Recommended Posts

Hello; :):):) I got a problem to understand a program which use for users to simply format their post, and they realted with the prototype object.i got some question from the following code;1) window.undefined = window.undefined;this.initDone = false;return this._target == undefined;The above all from the follwoing code which i had highlighted.does the undefined and initDone and _target are prebuild property, if so, but i could not find them http://www.w3schools.com/js/default.asp to see what they do. or they just named by user.2)what the following function do?var BBCode = function(){ window.undefined = window.undefined; this.initDone = false; } Does it create a new instance of BBCode object?what does the window.undefined = window.undefined; and this.initDone = false; do?3)BBCode.prototype.init = function(t){ if(this.initDone) // what does it means here? return false; if(t == undefined) // what does it means here? return false; this._target = t? document.getElementById(t) : t; // what does it means here?this.initDone = true; return true; } 4)BBCode.prototype.noForm = function(){ return this._target == undefined; // what does it means here?} <html><head><script type="text/javascript"> var BBCode = function(){ window.undefined = window.undefined; this.initDone = false; } BBCode.prototype.init = function(t){ if(this.initDone) return false; if(t == undefined) return false; this._target = t? document.getElementById(t) : t; this.initDone = true; return true; } BBCode.prototype.noForm = function(){ return this._target == undefined; } </script>

</head><body><script type="text/javascript">//////////////////////////////////////////////////// insertcode is used for bold, italic, underline and quote and just // wraps the tags around a selection or prompts the user for some // text to apply the tag to BBCode.prototype.insertCode = function (tag, desc, endtag) { if(this.noForm()) return false; var isDesc = (desc == undefined ¦¦ desc == '')? false : true; // our textfield var textarea = this._target; // our open tag var open = '['+tag+']'; var close = '[/'+((endtag == undefined)? tag : endtag)+']'; if (!textarea.setSelectionRange) { var selected = document.selection.createRange().text; if (selected.length<=0) { // no text was selected so prompt the user for some text textarea.value += open+((isDesc)? prompt("Please enter the text you'd like to "+desc, "")+close : ''); }else{// put the code around the selected text document.selection.createRange().text = open+selected+((isDesc)? close : ''); }} else { // the text before the selection var pretext = textarea.value.substring(0, textarea.selectionStart); // the selected text with tags before and after var codetext = open+textarea.value.substring(textarea.selectionStart, textarea.selectionEnd)+((isDesc)? close : ''); // the text after the selection var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length); // check if there was a selection if (codetext == open+close) { //prompt the user codetext = open+((isDesc)? prompt("Please enter the text you'd like to "+desc, "")+close : ''); }// update the text field textarea.value = pretext+codetext+posttext; }// set the focus on the text field textarea.focus(); }//////////////////////////////////////////////////////////// inserts an image by prompting the user for the url BBCode.prototype.insertImage = function (html) { if(this.noForm()) return false; var src = prompt('Please enter the url', 'http://'); this.insertCode('img='+src); }/////////////////////////////////////////////////////////////////// inserts a link by prompting the user for a url BBCode.prototype.insertLink = function (html) { if(this.noForm()) return false; this.insertCode('url='+prompt("Please enter the url", "http://"), 'as text of the link', 'url') } </script><script type="text/javascript"> var bb = new BBCode(); </script> <input type="button" onclick="bb.insertCode('B', 'bold');" value="B" title="Bold text" /> <input type="button" onclick="bb.insertCode('I', 'make italic');" value="I" title="Italic text" /> <input type="button" onclick="bb.insertCode('U', 'underline');" value="U" title="Underlined text" /><input type="button" onclick="bb.insertImage();" value="Image" title="Inset an image" /> <input type="button" onclick="bb.insertLink();" value="Link" title="Insert a link" /><br /> <textarea id="ttt" name="ttt" rows="20"></textarea> <script type="text/javascript"> bb.init('ttt'); </script> </body></html>

Link to comment
Share on other sites

I'm actually lost on what the questions are in this post, but somewhere in there I think you ask what "window.undefined = window.undefined" does. It's basically for older browsers, they don't have "undefined" in the global context, so you're just adding it in.The rest of the questions seem to be asking the same sort of things. If you're looking at something like:return a == bit'll return true if a is equal to b, or false if it's not.

Link to comment
Share on other sites

I'm actually lost on what the questions are in this post, but somewhere in there I think you ask what "window.undefined = window.undefined" does. It's basically for older browsers, they don't have "undefined" in the global context, so you're just adding it in.The rest of the questions seem to be asking the same sort of things. If you're looking at something like:return a == bit'll return true if a is equal to b, or false if it's not.
i am sorry that i confuse you.My question is;1) does the .undefined is like the prebuild object's property? for example, the .length property of String of object.2) .initDone: what does it means ? 3) what the following code does?var BBCode = function(){ window.undefined = window.undefined; this.initDone = false; } 4) what the following code does? and what does the ._target means?BBCode.prototype.init = function(t){ if(this.initDone)return false; if(t == undefined)return false; this._target = t? document.getElementById(t) : t; this.initDone = true; return true; } 5) what does the following code do?BBCode.prototype.noForm = function(){ return this._target == undefined; }
Link to comment
Share on other sites

you may want to ask the author of that code. Those properties and methods are user defined.
i think you are right. It doen't affect the performance when i changed their name of properties and method.I found it from google, i will give up this code, because i got another one and i feel it is easier to understand than this one.Thanks :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...