39 lines
1.4 KiB
Plaintext
39 lines
1.4 KiB
Plaintext
Reading a non-existent property on an object always returns ``++undefined++``. Doing so is usually an error; either in the name of the property or the type of the variable being accessed.
|
|
|
|
|
|
If an attempt is made to access properties of a primitive, the primitive is automatically encased in a primitive-wrapper object for the operation. But being "promoted" to an object doesn't mean that the primitive will actually have properties to access. The wrapper object still won't have the non-existent property and ``++undefined++`` will be returned instead.
|
|
|
|
|
|
This rule raises an issue when an attempt is made to access properties of a primitive. Thus this rule should only be activated when you don't use monkey patching for standard objects, like ``++Number++``, ``++Boolean++`` and ``++String++``.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
x = 42;
|
|
y = x.length; // Noncompliant, Number type doesn't have "length" property
|
|
----
|
|
|
|
|
|
== Exceptions
|
|
|
|
The Ember framework introduces a few extensions to ``++String++``. Since it is a widely used package, the following ``++String++`` properties will not trigger this rule even though they are not built-in:
|
|
|
|
* ``++camelize++``
|
|
* ``++capitalize++``
|
|
* ``++classify++``
|
|
* ``++dasherize++``
|
|
* ``++decamelize++``
|
|
* ``++fmt++``
|
|
* ``++loc++``
|
|
* ``++underscore++``
|
|
* ``++w++``
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|