constructor definition in javascript

Dear Experts,

I get confused with the terminology, constructor, in javascript , it always show in javascript
document or internet article.

Question-1

For example,
function test() {}
var b= new test()
where test() is function constructor always described in those article   What is constructing ?

Question-2

var mesg="hello";
console.log(mesg); //hello
var mess = new String("hello") ;
console.log(mesg) //String{0:"h",1:"e",2:"l",3:"l",4:"o",Length:5}
console.log(mesg.constructor);  //function String(){ [ native code ] }

What is mesg constructing from mesg.constructor ? What there is [native code] meaning ?
What is native meaning in javascript( i.e. bulit-in code or function) ?

Question-3.

Could we show all String function code inside instead of [native code], OR it is not allowed on browser ?

Question-4.

Is it exactly same meaning of constructor in javascript as in C++ such using "::"

Please advise

Rwniceing
LVL 1
rwniceingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

trinitrotolueneDirector - Software EngineeringCommented:
constructor can be viewed as a prototype from which an object is created. You can retrieve the constructor for a function object and it can be used if you need to relate a function object to its creation.

In a way it is similar to the constructor concept that is seen in other OO languages like C++ and Java.

Take a look at
http://javascript.info/tutorial/constructor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trinitrotolueneDirector - Software EngineeringCommented:
The constructor property returns the constructor function for an object. This enables you to decide the type of the function object.
0
rwniceingAuthor Commented:
You're answering  Q1 and  Q4
In your reply to question 1,
string.prototype = { constructor: function(){ [native code]} }
So  constructor  is just   object string  protoptype's property which is named  with constructor.
Accessing Sting.constructor will show function(){[native code]} such as in quesiton-2
So constructor is just built-in object prototype property, nothing is special, Right ?

To question-4, I think so,  other epxerts agree it ?

Could you also answer Q2 and Q3, thanks for your reply

Rwniceing
0
rwniceingAuthor Commented:
The question-2 answer  is referred to  question-1 rely  and  tutorial constuctor javascript link at http://dmitrysoshnikov.com/ecmascript/javascript-the-core/
and Question-3 and native code is referenced in , for example, for chrome browser V8 engine which is written in C++ at  https://code.google.com/p/v8/
0
rwniceingAuthor Commented:
Thanks for your reply
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.