Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

JavaScript Prototyping: Extending Built-in Objects with Custom Functions

JavaScript's prototype system is one of its most powerful (and sometimes misunderstood) features. It allows you to add new methods and properties to existing objects, including native types like Arrays, Numbers, and Objects. In this guide,…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

JavaScript's prototype system is one of its most powerful (and sometimes misunderstood) features. It allows you to add new methods and properties to existing objects, including native types like Arrays, Numbers, and Objects. In this guide, we'll explore how prototyping works and demonstrate practical examples of extending built-in objects.






Understanding JavaScript Prototypes



Every JavaScript object has a hidden [[Prototype]] property that links to another object. When you try to access a property that doesn't exist on an object, JavaScript looks up the prototype chain until it finds the property or reaches null.






The Prototype Chain






const arr = [1, 2, 3];
console.log(arr.__proto__ === Array.prototype); // true
console.log(Array.prototype.__proto__ === Object.prototype); // true
console.log(Object.prototype.__proto__); // null









Extending Built-in Objects



While extending native prototypes is controversial (it can cause conflicts in large codebases), it can be useful for utility functions you use frequently.






1. Adding a Method to Arrays



Let's create a sum() method for arrays:




Array.prototype.sum = function() {
return this.reduce((total, num) => total + num, 0);
};

const numbers = [1, 2, 3, 4];
console.log(numbers.sum()); // 10









2. Adding a Method to Numbers/Integers



We can add a square() method to all numbers:




Number.prototype.square = function() {
return this * this;
};

const num = 5;
console.log(num.square()); // 25









3. Adding a Method to Objects



Let's add a deepClone() method to all objects:




Object.prototype.deepClone = function() {
return JSON.parse(JSON.stringify(this));
};

const original = { a: 1, b: { c: 2 } };
const clone = original.deepClone();
clone.b.c = 3;
console.log(original.b.c); // 2 (unchanged)









Best Practices for Prototyping





  1. Check for Existing Methods First




   if (!Array.prototype.sum) {
Array.prototype.sum = function() { /* ... */ };
}








  1. Use Object.defineProperty for Non-Enumerable Methods




   Object.defineProperty(Array.prototype, 'sum', {
value: function() { /* ... */ },
enumerable: false // Won't show up in for...in loops
});








  1. Consider Alternatives
    For shared code, consider utility functions instead:




   function sumArray(arr) {
return arr.reduce((t, n) => t + n, 0);
}









Advanced Example: Chaining Custom Methods






Array.prototype.square = function() {
return this.map(n => n * n);
};

Array.prototype.average = function() {
return this.sum() / this.length;
};

const results = [1, 2, 3].square().average();
console.log(results); // 4.666... (average of [1, 4, 9])









When Not to Modify Prototypes




  1. In large team projects where naming conflicts might occur

  2. When working with third-party libraries that might expect default behavior

  3. For properties/methods that might become native JavaScript features in the future






Conclusion



JavaScript's prototype system offers powerful capabilities for extending built-in objects. While you should use this feature judiciously, understanding prototypes is crucial for advanced JavaScript development. Whether you choose to extend native prototypes or create utility functions, the prototype chain remains fundamental to how JavaScript works.






Feel Free To Ask Questions, Happy coding! 🚀

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - JavaScript Prototyping: Extending Built-in Objects with Custom Functions
id: ae911cc3-7164-4a93-9a6d-51099e865414
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "JavaScript Prototyping: Extend" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("JavaScript Prototyping Extending Built-i")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*JavaScript Prototyping Extending Built-i*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "JavaScript Prototyping Extending Built-i"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich JavaScript Prototyping: Extending Built-.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten JavaScript Prototyping: Extending Built-in Objects with Custom Functions

Thematisch verwandte Begriffe: JavaScript, Prototyping, Extending, Builtin · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100372 | ClipBucket v5 before 5.5.3-#197 contains a path traversal vulnerability…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag