What does it mean window.property in js?
Posted Chuck Lu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了What does it mean window.property in js?相关的知识,希望对你有一定的参考价值。
What does it mean window.property in js?
window
is a global object in JavaScript that represents the window of the browser. It has many built-in properties and methods that are available to all scripts running in the window.
When you create a property on the window
object, you are creating a global variable that can be accessed from anywhere in the script. For example, if you set window.myVariable = "Hello world"
, you can access the value of myVariable
from any other script running in the same window by referring to window.myVariable
.
In general, it\'s not a good practice to create global variables as it can lead to naming conflicts and make the code harder to maintain. It\'s better to use variables with a narrower scope, such as those defined within a function or a module.
But I only see someone use
var tempUrl="";
then the window get a property named as tempUrl, how does this work?
When you declare a variable using the var
keyword in the global scope, it automatically becomes a property of the window
object in the browser.
So when you declare a variable like this:
var tempUrl = "";
it creates a property on the window
object called tempUrl
, and you can access it using:
window.tempUrl
or simply:
tempUrl
This is because window
is the global object in the browser, and any variable declared in the global scope becomes a property of the window
object.
any variable declared in the global scope becomes a property of the window object. Which documentation defines this?
This behavior is defined in the ECMAScript specification, which is the official specification for the JavaScript language. Specifically, the ECMAScript specification states that "The global object is the object that is the outermost object of the JavaScript object hierarchy" (source: ECMAScript Language Specification, Section 8.1).
In web browsers, the global object is the window
object, which is the top-level object for JavaScript code running in the browser environment. When a variable is declared in the global scope, it becomes a property of the window
object by default. This behavior is described in the W3C DOM specification, which states that "Variables declared globally become properties of the global object" (source: https://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html#GlobalBinding).
What\'s the default global object of a simple js file?
The default global object in a simple JS file is the window
object, which represents the browser window or tab in which the script is running. This object is automatically created by the browser and provides a global namespace for all the JavaScript code running within the window.
In a Node.js environment, the global object is different and is called global
. It provides a similar namespace for all the JavaScript code running within a Node.js process.
Helix, what does it mean for Sitecore CMS development?
If you look at 10 different Sitecore solutions from the last few years you will most likely find 10 totally different types of architecture. As a developer picking up a solution from a third party or even internally this variance can mean a significant “Bedding in” period while you get a feel for the patterns being used.
Sitecore are attempting to standardize the approach taken to developing Sitecore solutions with Helix and Habitat.
Helix (http://helix.sitecore.net/) is a set of conventions that developers should be using when developing new websites.
Habitat (https://github.com/Sitecore/Habitat) is an example implementation of the Helix conventions.
Helix is based on the principles of package design which were created with the intention of creating software that is easy to maintain and extend. The principles of package design are an extension of the SOLID principles of class design but applied to packages of software.
I am not going to go into the principles here however if you want to spend some time understanding these a good book to read would be “Agile Software Development, Principles, Patterns, and Practices” by Robert C. Martin.
Why Should I Care?
As a Sitecore developer over the next few years you are likely to start seeing Helix compliant solutions more and more. Following the conventions should allow you to create software that is easier to maintain and extend.
Helix is a fairly large step away from more traditional “Type centric” solutions and understanding the why and how of Helix is going to allow you to pick up and develop solutions using these principles a lot faster than you have picked up solutions in the past.
A good place to get started is to go to the Habitat wiki and follow the “Getting Started” exercises (https://github.com/Sitecore/Habitat/wiki).
以上是关于What does it mean window.property in js?的主要内容,如果未能解决你的问题,请参考以下文章
Tasks, Workers, Threads, Scheduler, Sessions, Connections, Requests – what does it all mean?
"Batch,Batch,Batch":What does it really mean?
What does -1 mean in numpy reshape?