javascript styles

in #javascript2 years ago (edited)

Are you using "" or '' in javascript?

Are you using ; or none at the end of line?

Let's see how to use it in open source.


1.jQuery

using : "" and ;

API example

https://jquery.com/

$.ajax({
url: "/api/getWeather",
data: {
zipcode: 97201
},
success: function( result ) {
$( "#weather-temp" ).html( "" + result + " degrees" );
}
});

Code example

https://github.com/jquery/jquery/blob/main/src/core/ready.js

if ( document.readyState !== "loading" ) {
window.setTimeout( jQuery.ready );
}


2.bootstrap

using : '' and none

Code example

https://github.com/twbs/bootstrap/blob/main/js/src/button.js

const NAME = 'button'
const DATA_KEY = 'bs.button'
const EVENT_KEY = .${DATA_KEY}
const DATA_API_KEY = '.data-api'


3.angular

using : '' and ;

https://github.com/angular/angular/blob/main/packages/core/src/application_tokens.ts

export const PLATFORM_ID = new InjectionToken('Platform ID', {
providedIn: 'platform',
factory: () => 'unknown', // set a default platform name, when none set explicitly
});


4.vue

using : '' and none

https://github.com/vuejs/vue/blob/main/src/core/components/keep-alive.ts

function matches(
pattern: string | RegExp | Array,
name: string
): boolean {
if (isArray(pattern)) {
return pattern.indexOf(name) > -1
} else if (typeof pattern === 'string') {
return pattern.split(',').indexOf(name) > -1
} else if (isRegExp(pattern)) {
return pattern.test(name)
}
return false
}


5.react

using : '' and ;

https://github.com/facebook/react/blob/main/packages/react-dom/src/client/ReactDOM.js

function createPortal(
children: ReactNodeList,
container: Element | DocumentFragment,
key: ?string = null,
): React$Portal {
if (!isValidContainer(container)) {
throw new Error('Target container is not a DOM element.');
}
return createPortalImpl(children, container, null, key);
}

Sort:  

@pishio

What about your site which we used to drop our post link and you manually curate them. Is it still working or stopped for some reason?

The bots operating on my site have been stopped. There were a lot of spam users there.

Hmm. That's OK.

I prefer to use '' and ; at the end of line in JS. Because nearly all languages uses ; at the end of line and '' looks better than "" for me.