[Javascript] Link to Other Objects through the JavaScript Prototype Chain
JavaScript to The Link prototype Objects Chain Through
2023-09-14 09:00:49 时间
Objects have the ability to use data and methods that other objects contain, as long as it lives on the [prototype] chain. In this lesson we’ll test this out by adding properties and working with this linkage of properties.
const obj = {firstName: 'Tyler'}; const protoObj = {lastName: 'Clark'}; Object.setPrototypeOf(obj, protoObj);
We can access the 'lastNmae' by calling:
obj.lastName
If we set:
obj.lastName = "Wan"
So now if we console.log obj.lastName it logs:
obj.lastName // Wan obj.__proto__.lastName //Clark
We we delete:
delete obj.lastName
相关文章
- [Javascript] Link to Other Objects through the JavaScript Prototype Chain (Object.setPrototypeOf())
- [Javascript] Compare a Generator to Using Array Map and Filter
- [Javascript] Convert a Callback-Based JavaScript Function to a Promise-Based One
- [Javascript] AbortController to cancel the fetch request
- [Javascript Crocks] Apply a function in a Maybe context to Maybe inputs (curry & ap & liftA2)
- [SCSS] Convert SCSS Variable Arguments to JavaScript
- [Javascript] How to write a Javascript libarary
- [Immutable.js] Converting Immutable.js Structures to Javascript and other Immutable Types
- [Javascript] Adding Shapes to Maps with Leaflet and GeoJSON
- 单线程的JavaScript
- [Rust] Pass a JavaScript Function to WebAssembly and Invoke it from Rust
- [Javascript] Function Expression Ex, Changing Declarations to Expressions
- JavaScript一次性定时器的设置和取消
- 【华为OD机试 2023】等和子数组最小和(C++ Java JavaScript Python)
- javascript基金会——鼠标事件,系统对话框,等等。