Thread: Functions
View Single Post
  #4 (permalink)  
Old July 7th, 2006, 02:09 PM
AGS AGS is offline
Wrox Technical Editor
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: Russia
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would say that the main difference is that the function created using Function constructor contains only global object in its scope chain. It can be illustrated by following example:
Code:
        function myFunc() {

            var myVar = "Test";

            var oCar = { color: "Red" };

            oCar.showColor = function () {
                alert(this.color);
                alert(typeof myVar);
            };

            oCar.showColor1 = new Function ('alert(this.color); alert(typeof myVar); ');           

            return oCar;        
        }

        var car = myFunc();

        car.showColor();
        car.showColor1();

Am I wrong, Nicholas?

Best regards,
Alexei