javascript and jshint, undefined - Stack Overflow

Today I wrote this code:(function (window) {'use strict';function ViewPort() {var getSize = f

Today I wrote this code:

(function (window) {
    'use strict';

    function ViewPort() {
        var getSize = function () {
                var e = window,
                    a = 'inner';

                if (!('innerWidth' in window)) {
                    a = 'client';
                    e = Document.documentElement || Document.body;
                }
                return { width : e[a + 'Width'], height : e[a + 'Height'] };
            },

            update = function () {
                var vw = (getSize().width / 100);

                Document.querySelector('html').style.fontSize = vw + 'px';
            };

        Document.addEventListener("resize", update());
    }

    function run() {
        return new ViewPort();
    }

    window.viewport = run;
}(window));

window.onload = function () {
    'use strict';
    viewport();
};

When I use jshint then I got errors like this:

11  'Document' is not defined. (W117)   e = Document.documentElement || Document.body;
19  'Document' is not defined. (W117)   Document.querySelector('html').style.fontSize = vw + 'px';
22  'Document' is not defined. (W117)   Document.addEventListener("resize", update());
30  'window' is not defined. (W117) }(window));
32  'window' is not defined. (W117) window.onload = function () {
34  'viewport' is not defined. (W117)   viewport();

any one can help me fix my errors? I dont have any idea how to fix it, This code I have in scripts.js file not inline.

Today I wrote this code:

(function (window) {
    'use strict';

    function ViewPort() {
        var getSize = function () {
                var e = window,
                    a = 'inner';

                if (!('innerWidth' in window)) {
                    a = 'client';
                    e = Document.documentElement || Document.body;
                }
                return { width : e[a + 'Width'], height : e[a + 'Height'] };
            },

            update = function () {
                var vw = (getSize().width / 100);

                Document.querySelector('html').style.fontSize = vw + 'px';
            };

        Document.addEventListener("resize", update());
    }

    function run() {
        return new ViewPort();
    }

    window.viewport = run;
}(window));

window.onload = function () {
    'use strict';
    viewport();
};

When I use jshint then I got errors like this:

11  'Document' is not defined. (W117)   e = Document.documentElement || Document.body;
19  'Document' is not defined. (W117)   Document.querySelector('html').style.fontSize = vw + 'px';
22  'Document' is not defined. (W117)   Document.addEventListener("resize", update());
30  'window' is not defined. (W117) }(window));
32  'window' is not defined. (W117) window.onload = function () {
34  'viewport' is not defined. (W117)   viewport();

any one can help me fix my errors? I dont have any idea how to fix it, This code I have in scripts.js file not inline.

Share Improve this question asked Jan 28, 2015 at 13:30 axlplaxlpl 4832 gold badges8 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Javascript is case sensitive. document is all lowercase. It should work, then.

If that still doesn't work, you could try adding a directive to the start of your file to imply that the script is meant for the browser, and the browser globals are available.

Add this ment to the top of your script:

/* jshint browser: true */

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745438310a4627712.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信