ÐÑибка ÑÑÑогого Ñежима JavaScript "can't assign to property" ("невозможно пÑиÑвоиÑÑ ÑвойÑÑво") пÑоиÑÑ Ð¾Ð´Ð¸Ñ Ð² ÑÐ¾Ñ Ð¼Ð¾Ð¼ÐµÐ½Ñ, когда Ð²Ñ Ð¿ÑÑаеÑеÑÑ ÑоздаÑÑ ÑвойÑÑво пÑимиÑивного Ñипа даннÑÑ (Ñакого как Ñимвол, ÑÑÑока, ÑиÑло или бÑлевое знаÑение). ÐÑимиÑивнÑе ÑÐ¸Ð¿Ñ Ð´Ð°Ð½Ð½ÑÑ Ð½Ðµ могÑÑ ÑодеÑжаÑÑ Ð½Ð¸ÐºÐ°ÐºÐ¸Ñ ÑвойÑÑв.
MessageTypeError: can't assign to property "x" on {y}: not an object> (Firefox) TypeError: Cannot create property 'x' on {y} (Chrome)Error type What went wrong?
In Strict_mode
, a TypeError
is raised when attempting to create a property on primitive value such as a symbol, a string, a number or a boolean. Primitive values cannot hold any property.
The problem might be that an unexpected value is flowing at an unexpected place, or that an object variant of a String
or a Number
is expected.
"use strict";
var foo = "my string";
// The following line does nothing if not in strict mode.
foo.bar = {}; // TypeError: can't assign to property "bar" on "my string": not an object
Fixing the issue
Either fix the code to prevent the primitive from being used in such places, or fix the issue is to create the object equivalent Object
.
"use strict";
var foo = new String("my string");
foo.bar = {};
СмоÑÑиÑе Ñакже
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4