要求('use-strict')对我不起作用

require('use-strict') doesn't work for me

在这里,我试图设置只读值 属性 但我没有收到任何错误:

这是我的代码:

require('use-strict');

function Employee(firstname) {
    var _firstname = firstname;

    Object.defineProperty(this, 'firstName', {
        get: function () { return _firstname },
        //set: function (value) { _firstname = value }
    });
}

var employee = new Employee('Fawad');

employee.firstName = 'Yasir'; //Attempting to set a value for read-only property.

console.log(employee.firstName);

来自 use-strict 包的文档:

The implementation works by patching Node's internal module.wrapper array, and then freezing it, so that further modifications are not possible.

Also, this means that the current module will not be affected. You should still "use strict" in the module that does require('use-strict'). This module applies strictness to all future modules loaded by your program.

使用"use strict";尽管这种方法通常用于 JavaScript 开发,但页面顶部对我有用。我试图使用 node.js 软件包之一,但没有用。