1. ホーム
  2. js

jsオブジェクト(3)

2022-02-08 22:16:03
<パス
  1. JavaScriptにおけるオブジェクトの分類

    A. ホストオブジェクト JavaScript のホスト環境によって提供されるオブジェクトで、その動作はホスト環境によって完全に決定されます。
    ブラウザオブジェクト

    B. 組み込みオブジェクト JavaScript 言語が提供するオブジェクト

     a. Intrinsic objects Instances of objects that are automatically created with JavaScript runtime creation, as specified by the standard
         Three values:
             Infinity, NaN, undefined
         Nine functions:
             eval
             isFinite
             isNaN
             parseFloat
             parseInt
             decodeURI
             decodeURIComponent
             encodeURI
             encodeURIComponent
         Some constructors:
             Array, Date, RegExp, Promise, Proxy, Map, WeakMap, Set, WeakSet, Function, Boolean, String, Number, Symbol, Object, Error, EvalError, RangeError. ReferenceError, SyntaxError, TypeError, URIError, ArrayBuffer, SharedArrayBuffer, DataView, Typed Array, Float32Array, Float64Array Int8Array, Int16Array, Int32Array, UInt8Array, UInt16Array, UInt32Array, UInt8ClampedArray.
         Four objects used as namespaces.
             Atomics
             JSON
             Math
             Reflect
         Find all intrinsic objects : Use breadth-first search to find all properties and Getters/Setters of these objects to get all intrinsic objects of JS
    
             var set = new Set();
             var objects = [eval,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Array,Date,RegExp, Promise,Proxy,Map,WeakMap,Set,WeakSet,Function,Boolean,String,Number,Symbol,Object,Error,EvalError,RangeError,ReferenceError, SyntaxError,TypeError,URIError,ArrayBuffer,SharedArrayBuffer,DataView,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array, Uint8Array,Uint16Array,Uint32Array,Uint8ClampedArray,Atomics,JSON,Math,Reflect];
             objects.forEach(o => set.add(o));
    
             for(var i = 0; i < objects.length; i++) {
                 var o = objects[i]
                 for(var p of Object.getOwnPropertyNames(o)) {
                     var d = Object.getOwnPropertyDescriptor(o, p)
                     if( (d.value ! == null && typeof d.value === "object") || (typeof d.value === "function"))
                         if(!set.has(d.value))
                             set.add(d.value), objects.push(d.value);
                     if( d.get )
                         if(!set.has(d.get))
                             set.add(d.get), objects.push(d.get);
                     if( d.set )
                         if(!set.has(d.set))
                             set.add(d.set), objects.push(d.set);
                 }
             }
    
     b. Native objects Objects that can be created by the user through built-in constructors such as Array, RegExp, or special syntax
        New objects can be created by the new operation, called native objects
    
             typeof new Date // object
             typeof Date() // string
             Their implementations of [[call]] [[construct]] do not always have the same result
    
             The execution process of new:
                 A. create a new object using the prototype property of the constructor as the prototype
                 B. Pass this and the call argument to the constructor for execution
                 C. If the constructor returns an object, return it, otherwise return to the first step of creation
    
             [[construct]] execution procedure:
                 Create a new object with Object.prototype as the prototype.
                 Execute the [[call]] of the function with the new object as this.
                 If the return value of [[call]] is an object, then this object is returned, otherwise the new object created in the first step is returned.
    
                     function cls(){
                         this.a = 100;
                         return {
                             getValue:() => this.a
                         }
                     }
                     var o = new cls;
                     o.getValue(); //100
                     //a is never accessible outside
    
             Special Behavior Objects
                 Array: The length property of Array changes automatically based on the largest subscript.
                 Object.prototype: as the default prototype of all normal objects, you can't set a prototype for it anymore.
                 String: To support subscript operations, access to the positive integer property of String goes to the string.
                 Arguments: the non-negative integer subscript property of arguments is linked to the corresponding variable.
                 The namespace object of the module: it has many special features and is completely different from the normal object, so try to use it only for import.
                 Arrays of types and array buffers: associated with memory blocks, with special subscripting operations.
                 function after bind: associated with the original function.
    
        * Constructors in JS:
    
              Basic types
                  Boolean
                  String
                  Number
                  Symbol
                  Object
    
              Basic Functions and Data Structures
                  Array
                  Date
                  RegExp
                  Promise
                  Proxy
                  Map
                  WeakMap
                  Set
                  WeakSet
                  Function
    
              Error Type
                  Error
                  EvalError
                  RangeError
                  ReferenceRrror
                  SyntaxError
                  TypeError
                  URIError
    
              Binary Operations
                  ArrayBuffer
                  SharedArrayBuffer
                  DataView
    
              Arrays with types
                  Float32Array
                  Float64Array
                  int8Array
                  int16Array
                  int32Array
                  UInt8Array
                  UInt16Array
                  UInt32Array
                  UInt8ClampedArray
    
        Most of the objects created by these constructors use private fields:
             Error: [[ErrorData]]
             Boolean: [[BooleanData]]
             Number: [[NumberData]]
             Date: [[DateValue]]
             RegExp: [[RegExpMatcher]]
             Symbol: [[SymbolData]]
             Map: [[MapData]]
    
    
     c. Common object An object created by the {} syntax, the Object constructor, or the class keyword defining the class, which can be inherited by the prototype
    
         Function objects
             has a [[call]] private field
             The [[call]] private field must be a function defined in an engine that accepts this value and call parameters and generates a domain switch
         Constructor objects
             has [[construct]] private fields